Perl6-Export-0.07004075500007650000024000000000001002323131200127735ustar00damianstaffPerl6-Export-0.07/Changes010075500007650000024000000011121002323131200143400ustar00damianstaffRevision history for Perl extension Perl6::Export. 0.01 Sat Oct 11 23:28:24 2003 - original version; created by h2xs 1.22 with options -A -P -X -f -n Perl6::Export 0.02 Thu Nov 20 04:54:30 2003 0.03 Tue Dec 16 11:54:34 2003 - Improved handling of tags - Added ALWAYS tag 0.05 Fri Feb 27 04:10:29 2004 - Changed groups and ALWAYS to require prefix colon (as is likely in Perl 6) 0.05 Fri Feb 27 04:17:49 2004 0.06 Tue Mar 9 02:55:46 2004 - Changed interface in line with Larry's recent design decisions 0.07 Tue Mar 9 02:58:16 2004 - Minor doc bug fix Perl6-Export-0.07/Export.pm010075500007650000024000000106631002323131200146770ustar00damianstaffpackage Perl6::Export; our $VERSION = '0.07'; my $ident = qr{ [^\W\d] \w* }x; my $arg = qr{ : $ident \s* ,? \s* }x; my $args = qr{ \s* \( $arg* \) | (?# NOTHING) }x; my $defargs = qr{ \s* \( $arg* :DEFAULT $arg* \) }x; my $proto = qr{ \s* (?: \( [^)]* \) | (?# NOTHING) ) }x; sub add_to { my ($EXPORT, $symbol, $args, $decl) = @_; $args = "()" unless $args =~ /\S/; $args =~ tr/://d; return qq[BEGIN{no strict 'refs';] . qq[push\@$EXPORT,'$symbol';\$EXPORT{'$symbol'}=1;] . qq[push\@{\$EXPORT_TAGS\{\$_}},'$symbol' for ('ALL',qw$args)}$decl]; } sub false_import_sub { my $import_sub = q{ use base 'Exporter'; sub import { my @exports; for (my $i=1; $i<@_; $i++) { for ($_[$i]) { if (!ref && /^[:\$&%\@]?(\w+)$/ && ( exists $EXPORT{$1} || exists $EXPORT_TAGS{$1}) ) { push @exports, splice @_, $i, 1; $i--; } } } @exports = ":DEFAULT" unless @exports; __PACKAGE__->export_to_level(1, $_[0], ':MANDATORY', @exports); goto &REAL_IMPORT; } }; $import_sub =~ s/\n/ /g; $import_sub =~ s/REAL_IMPORT/$_[0]/g; return $import_sub; } my $MANDATORY = q[BEGIN{$EXPORT_TAGS{MANDATORY}||=[]}]; use Filter::Simple; use Digest::MD5 'md5_hex'; FILTER { return unless /\S/; my $real_import_name = '_import_'.md5_hex($_); my $false_import_sub = false_import_sub($real_import_name); my $real_import_sub = ""; s/ \b sub \s+ import \s* ([({]) /sub $real_import_name$1/x or $real_import_sub = "sub $real_import_name {}"; s{( \b sub \s+ ($ident) $proto) \s+ is \s+ export ($defargs) } { add_to('EXPORT',$2,$3,$1) }gex; s{( \b our \s+ ([\$\@\%]$ident) $proto) \s+ is \s+ exported ($defargs) } { add_to('EXPORT',$2,$3,$1) }gex; s{( \b sub \s+ ($ident) $proto ) \s+ is \s+ export ($args) } { add_to('EXPORT_OK',$2,$3,$1) }gex; s{( \b our \s+ ([\$\@\%]$ident) ) \s+ is \s+ export ($args) } { add_to('EXPORT_OK',$2,$3,$1) }gex; $_ = $real_import_sub . $false_import_sub . $MANDATORY . $_; } __END__ =head1 NAME Perl6::Export - Implements the Perl 6 'is export(...)' trait =head1 SYNOPSIS # Perl 5 code... package Some::Module; use Perl6::Export; # Export &foo by default, when explicitly requested, # or when the ':ALL' export set is requested... sub foo is export(:DEFAULT) { print "phooo!"; } # Export &var by default, when explicitly requested, # or when the ':bees', ':pubs', or ':ALL' export set is requested... # the parens after 'is export' are like the parens of a qw(...) sub bar is export(:DEFAULT :bees :pubs) { print "baaa!"; } # Export &baz when explicitly requested # or when the ':bees' or ':ALL' export set is requested... sub baz is export(:bees) { print "baassss!"; } # Always export &qux # (no matter what else is explicitly or implicitly requested) sub qux is export(:MANDATORY) { print "quuuuuuuuux!"; } sub import { # This subroutine is called when the module is used (as usual), # but it is called after any export requests have been handled. # Those requests will have been stripped from its argument list } =head1 DESCRIPTION Implements what I hope the Perl 6 symbol export mechanism might look like. It's very straightforward: =over =item * If you want a subroutine to be capable of being exported (when explicitly requested in the C arguments), you mark it with the C trait. =item * If you want a subroutine to be automatically exported when the module is used (without specific overriding arguments), you mark it with the C trait. =item * If you want a subroutine to be automatically exported when the module is used (even if the user specifies overriding arguments), you mark it with the C trait. =item * If the subroutine should also be exported when particular export groups are requested, you add the names of those export groups to the trait's argument list. =back That's it. =head1 WARNING The syntax and semantics of Perl 6 is still being finalized and consequently is at any time subject to change. That means the same caveat applies to this module. =head1 DEPENDENCIES Requires Filter::Simple =head1 AUTHOR Damian Conway (damian@conway.org) =head1 BUGS AND IRRITATIONS Does not yet handle the export of variables. Comments, suggestions, and patches welcome. =head1 COPYRIGHT Copyright (c) 2003, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. Perl6-Export-0.07/Makefile.PL010075500007650000024000000002631002323131200150250ustar00damianstaff use ExtUtils::MakeMaker; WriteMakefile( NAME => q[Perl6::Export], VERSION => q[0.07], AUTHOR => 'Damian Conway', PREREQ_PM => { Filter::Simple=>0 }, ); Perl6-Export-0.07/MANIFEST010075500007650000024000000001101001754203500142050ustar00damianstaffChanges Export.pm Makefile.PL MANIFEST README t/1.t t/lib/TestModule.pm Perl6-Export-0.07/README010075500007650000024000000024711002323131200137360ustar00damianstaff============================================================================== Release of version 0.07 of Perl6::Export ============================================================================== Perl6/Export version 0.01 ========================= This module prototypes the Perl 6 'exported' and 'exportable' traits in Perl 5. Instead of messing around with @EXPORT arrays, you just declare which subs are to be exported (or are exportable on request) as part of those subs. For example: sub foo is exported { # by default ... } sub bar is exportable { # on request ... } INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Filter::Simple COPYRIGHT AND LICENCE Copyright (C) 2003 Damian Conway This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ============================================================================== CHANGES IN VERSION 0.07 - Minor doc bug fix ============================================================================== AVAILABILITY Perl6::Export has been uploaded to the CPAN ============================================================================== Perl6-Export-0.07/t004075500007650000024000000000001002323131200132365ustar00damianstaffPerl6-Export-0.07/t/1.t010075500007650000024000000011071001754204400136530ustar00damianstaff# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 1.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use lib 't/lib'; use Test::More tests=>5; use TestModule qw(:Q bar other); ok(foo, "Exported &foo (always)"); ok(bar, "Exported requested &bar"); ok(qux, "Exported grouped &qux"); ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. Perl6-Export-0.07/t/lib004075500007650000024000000000001002323131200140045ustar00damianstaffPerl6-Export-0.07/t/lib/TestModule.pm010075500007650000024000000004741002202424600165200ustar00damianstaffpackage TestModule; use Perl6::Export; sub foo is export(:MANDATORY) { return 1; } sub bar is export { return 1; } sub qux is export(:Q) { return 1; } sub import { Test::More::ok(1, "Invoked Module::import"); Test::More::ok("@_" eq "TestModule other", "Module::import received correct args"); } 1;