Skip to content
Browse files

initial implement

  • Loading branch information...
1 parent f2754f2 commit 7196e5578f0c1203e5609e1c978b3ee17bef937d @tokuhirom committed Oct 29, 2011
Showing with 51 additions and 4 deletions.
  1. +23 −4 lib/Exporter/Auto.pm
  2. +28 −0 t/01_simple.t
View
27 lib/Exporter/Auto.pm
@@ -4,7 +4,26 @@ use warnings;
use 5.008008;
our $VERSION = '0.01';
-
+use Sub::Identify qw(stash_name);
+use B::Hooks::EndOfScope;
+use Exporter;
+
+sub import {
+ my $klass = caller(0);
+
+ no strict 'refs';
+ unshift @{"${klass}::ISA"}, 'Exporter';
+
+ on_scope_end {
+ while (my ($k, $v) = each %{"${klass}::"}) {
+ next if $k =~ /^(?:BEGIN|CHECK|END)$/;
+ next if $k =~ /^_/;
+ next unless *{"${klass}::${k}"}{CODE};
+ next if $klass ne stash_name($klass->can($k));
+ push @{"${klass}::EXPORT"}, $k;
+ }
+ };
+}
1;
__END__
@@ -13,15 +32,15 @@ __END__
=head1 NAME
-Exporter::Auto -
+Exporter::Auto - Export public functions automatically.
=head1 SYNOPSIS
- use Exporter::Auto;
+ use Exporter::Auto;
=head1 DESCRIPTION
-Exporter::Auto is
+I'm tired to push function names to @EXPORT. Perl5 should add functions automatically!!!111
=head1 AUTHOR
View
28 t/01_simple.t
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+use utf8;
+use Test::More;
+
+{
+ package Thing;
+ use Exporter::Auto;
+ use File::Spec::Functions qw(catfile);
+ BEGIN {
+ $INC{'Thing.pm'}++;
+ }
+
+ sub foo {
+ 'ok'
+ }
+ sub _private {
+ }
+}
+
+use Thing;
+
+ok(__PACKAGE__->can('foo'));
+ok(!__PACKAGE__->can('_private'));
+ok(!__PACKAGE__->can('catfile'));
+
+done_testing;
+

0 comments on commit 7196e55

Please sign in to comment.
Something went wrong with that request. Please try again.