CC: | nothingmuch [...] woobling.org |
Subject: | Patch for Sub::Call::Tail to move to Sub::Exporter |
Date: | Tue, 14 Jun 2011 15:22:02 +0100 |
To: | bugs-Sub-Call-Tail [...] rt.cpan.org |
From: | Hakim Cassimally <hakim.cassimally [...] gmail.com> |
From 68b7f89af39c399bfe06bcea8dceefcb1058b9e7 Mon Sep 17 00:00:00 2001
From: Hakim Cassimally <hakim@eschew.local>
Date: Tue, 14 Jun 2011 15:09:22 +0100
Subject: Move to Sub::Exporter to allow import renaming
(Will be useful for examples in https://github.com/osfameron/pure-fp-book )
---
Changes | 3 +++
Makefile.PL | 1 +
lib/Sub/Call/Tail.pm | 11 +++++++----
t/05_as.t | 25 +++++++++++++++++++++++++
4 files changed, 36 insertions(+), 4 deletions(-)
create mode 100644 t/05_as.t
diff --git a/Changes b/Changes
index 92ec599..a650e4b 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+NEXT
+ - allow renaming of import with Sub::Exporter (osfameron)
+
0.04
- Correct fallback definition of AvREIFY_only (Andrew Rodland)
diff --git a/Makefile.PL b/Makefile.PL
index 0e6ae7f..8af7b87 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -12,6 +12,7 @@ all_from 'lib/Sub/Call/Tail.pm';
requires_external_cc;
requires 'parent';
+build_requires 'Sub::Exporter';
configure_requires 'ExtUtils::Depends' => 0.302; #minimum version
that works on Win32+gcc
foreach my $mod qw(B::Hooks::OP::Check::EntersubForCV) {
diff --git a/lib/Sub/Call/Tail.pm b/lib/Sub/Call/Tail.pm
index 3239ee4..9b5d394 100644
--- a/lib/Sub/Call/Tail.pm
+++ b/lib/Sub/Call/Tail.pm
@@ -4,15 +4,13 @@ use strict;
use warnings;
require 5.008001;
-use parent qw(Exporter DynaLoader);
+use parent qw(DynaLoader);
use B::Hooks::OP::Check::EntersubForCV;
+use Sub::Exporter -setup => { exports => [qw( tail )] };
our $VERSION = '0.04';
$VERSION = eval $VERSION;
-our @EXPORT = our @EXPORT_OK = qw(tail);
-our %EXPORT_TAGS = ( all => \@EXPORT_OK );
-
__PACKAGE__->bootstrap($VERSION);
pop our @ISA;
@@ -39,6 +37,11 @@ Sub::Call::Tail - Tail calls for subroutines and methods
# instead of @_ = @blah; goto &foo
tail foo(@blah);
+ # We use Sub::Exporter, so you can use a different keyword if it clashes
+ use Sub::Call::Tail 'tail' => { -as => 'tail_call' };
+
+ tail_call foo(@blah);
+
=head1 DESCRIPTION
This module provides a C<tail> modifier for subroutine and method calls that
diff --git a/t/05_as.t b/t/05_as.t
new file mode 100644
index 0000000..7a82b40
--- /dev/null
+++ b/t/05_as.t
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use Sub::Call::Tail tail => { -as => 'tail_call' };
+
+sub bar { "baz" };
+
+sub foo {
+ tail_call bar();
+}
+
+sub tests {
+ is foo(), 'baz', 'tail_call worked ok';
+}
+
+tests();
+
+done_testing;
+
+# ex: set sw=4 et:
+
--
1.6.6.1