Export-Attrs-v0.1.0000755001750001750 012657417674 15140 5ustar00powermanpowerman000000000000README100644001750001750 1521212657417674 16122 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0NAME Export::Attrs - The Perl 6 'is export(...)' trait as a Perl 5 attribute VERSION This document describes Export::Attrs version 0.000005 SYNOPSIS package Some::Module; use Export::Attrs; # Export &foo by default, when explicitly requested, # or when the ':ALL' export set is requested... sub foo :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 :Export(:DEFAULT :bees :pubs) { print "baaa!"; } # Export &baz when explicitly requested # or when the ':bees' or ':ALL' export set is requested... sub baz :Export(:bees) { print "baassss!"; } # Always export &qux # (no matter what else is explicitly or implicitly requested) sub qux :Export(:MANDATORY) { print "quuuuuuuuux!"; } # Allow the constant $PI to be exported when requested... use Readonly; Readonly our $PI :Export => 355/113; # Allow the variable $EPSILON to be always exported... our $EPSILON :Export( :MANDATORY ) = 0.00001; sub IMPORT { # This subroutine is called when the module is used (as usual), # but it is called after any export requests have been handled. }; DESCRIPTION NOTE: This module is a fork of Perl6::Export::Attrs created to restore compatibility with Perl6::Export::Attrs version 0.0.3. Implements a Perl 5 native version of what the Perl 6 symbol export mechanism will look like (with some unavoidable restrictions). It's very straightforward: * If you want a subroutine or package variable to be capable of being exported (when explicitly requested in the use arguments), you mark it with the :Export attribute. * If you want a subroutine or package variable to be automatically exported when the module is used (without specific overriding arguments), you mark it with the :Export(:DEFAULT) attribute. * If you want a subroutine or package variable to be automatically exported when the module is used (even if the user specifies overriding arguments), you mark it with the :Export(:MANDATORY) attribute. * If the subroutine or package variable should also be exported when particular export groups are requested, you add the names of those export groups to the attribute's argument list. That's it. IMPORT blocks Perl 6 replaces the import subroutine with an IMPORT block. It's analogous to a BEGIN or END block, except that it's executed every time the corresponding module is use'd. The IMPORT block is passed the argument list that was specified on the use line that loaded the corresponding module, minus the arguments that were used to specify exports. Note that, due to limitations in Perl 5, the IMPORT block provided by this module must be terminated by a semi-colon, unless it is the last statement in the file. DIAGNOSTICS %s does not export: %s\nuse %s failed You tried to import the specified subroutine or package variable, but the module didn't export it. Often caused by a misspelling, or forgetting to add an :Export attribute to the definition of the subroutine or variable in question. Bad tagset in :Export attribute at %s line %s: [%s] You tried to import a collection of items via a tagset, but the module didn't export any subroutines under that tagset. Is the tagset name misspelled (maybe you forgot the colon?). Can't export lexical %s variable at %s The module can only export package variables. You applied the :Export marker to a non-package variable (almost certainly to a lexical). Change the variable's my declarator to an our. Can't export anonymous subroutine at %s Although you can apply the :Export marker to an anonymous subroutine, it rarely makes any sense to do so, since that subroutine can't be exported without a name to export it as. Either give the subroutine a name, or make sure it's aliased to a named typeglob at compile-time (or, at least, before it's exported). CONFIGURATION AND ENVIRONMENT Export::Attrs requires no configuration files or environment variables. DEPENDENCIES This module requires the Attribute::Handlers module to handle the attributes. INCOMPATIBILITIES This module cannot be used with the Memoize CPAN module, because memoization replaces the original subroutine with a wrapper. Because the :Export attribute is applied to the original (not the wrapper), the memoized wrapper is not found by the exporter mechanism. LIMITATIONS Note that the module does not support exporting lexical variables, since there is no way for the exporter mechanism to determine the name of a lexical and hence to export it. Nor does this module support the numerous addition export modes that Perl 6 offers, such as export-as-lexical or export-as-state. SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at https://github.com/powerman/perl-Export-Attrs/issues. You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. Feel free to fork the repository and submit pull requests. https://github.com/powerman/perl-Export-Attrs git clone https://github.com/powerman/perl-Export-Attrs.git Resources * MetaCPAN Search https://metacpan.org/search?q=Export-Attrs * CPAN Ratings http://cpanratings.perl.org/dist/Export-Attrs * AnnoCPAN: Annotated CPAN documentation http://annocpan.org/dist/Export-Attrs * CPAN Testers Matrix http://matrix.cpantesters.org/?dist=Export-Attrs * CPANTS: A CPAN Testing Service (Kwalitee) http://cpants.cpanauthors.org/dist/Export-Attrs AUTHOR Alex Efros Damian Conway COPYRIGHT AND LICENSE This software is Copyright (c) 2016 by Alex Efros . Copyright (c) 2005,2015 Damian Conway . All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Changes100644001750001750 142512657417674 16516 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0Revision history for Export-Attrs v0.1.0 2016-02-12 20:08:54 EET - Based on Perl6::Export::Attrs 0.000005. - Renamed to Export::Attrs. - Migrate to Dist::Milla. - Fix a 0.000004 regression in exporting subroutines. 0.000005 2015-11-24 09:16:01 - Added dependency for PadWalker (thanks Dave!) 0.000004 2015-10-03 12:42:22 - Added export of package variables. - Fixed filtering of args to IMPORT block (thanks Smylers) - Updated docs to explain the syntactic constraints of the IMPORT block (thanks Smylers) - Updated docs to note incompatibility with Memoize.pm (thanks David) - Included META files (thanks Jarkko) 0.0.3 2005-08-02 05:53:06 - No changes logged 0.0.2 2005-08-02 05:52:27 - No changes logged 0.0.1 2005-03-27 06:48:42 - Initial release. LICENSE100644001750001750 4374312657417674 16261 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0This software is copyright (c) 2016 by Alex Efros . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2016 by Alex Efros . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2016 by Alex Efros . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End cpanfile100644001750001750 10612657417674 16702 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0requires 'PadWalker'; on test => sub { requires 'Test::More'; }; dist.ini100644001750001750 45112657417674 16645 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0[@Milla] [MetaProvides::Package] [Substitute] code = s/^(This document describes \S+ version |VERSION=['"])([^'"]*)/my($s,$v)=($1,$2);my%h=%Term::ReadLine::Gnu::Attribs;$s.($h{prompt}?($h{line_buffer}||$h{prompt}=~m{ \[(.*)\]})[0]:$v)/e [GitHubREADME::Badge] badges = travis badges = coveralls Build.PL100644001750001750 25712657417674 16501 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0# This Build.PL for Export-Attrs was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.014. use strict; use warnings; use 5.006; use Module::Build::Tiny 0.034; Build_PL(); META.yml100644001750001750 167012657417674 16476 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0--- abstract: "The Perl 6 'is export(...)' trait as a Perl 5 attribute" author: - 'Alex Efros ' build_requires: Test::More: '0' configure_requires: Module::Build::Tiny: '0.034' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.043, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Export-Attrs no_index: directory: - eg - examples - inc - share - t - xt provides: Export::Attrs: file: lib/Export/Attrs.pm version: v0.1.0 requires: PadWalker: '0' resources: bugtracker: https://github.com/powerman/perl-Export-Attrs/issues homepage: https://github.com/powerman/perl-Export-Attrs repository: https://github.com/powerman/perl-Export-Attrs.git version: v0.1.0 x_contributors: - 'Damian Conway ' - 'Niko Tyni ' MANIFEST100644001750001750 37312657417674 16335 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.043. Build.PL Changes LICENSE MANIFEST META.json META.yml README cpanfile dist.ini lib/Export/Attrs.pm t/00.load.t t/01export.t t/author-pod-syntax.t t/release-distribution.t META.json100644001750001750 332712657417674 16647 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0{ "abstract" : "The Perl 6 'is export(...)' trait as a Perl 5 attribute", "author" : [ "Alex Efros " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.043, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Export-Attrs", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.034" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.15", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "PadWalker" : "0" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "provides" : { "Export::Attrs" : { "file" : "lib/Export/Attrs.pm", "version" : "v0.1.0" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/powerman/perl-Export-Attrs/issues" }, "homepage" : "https://github.com/powerman/perl-Export-Attrs", "repository" : { "type" : "git", "url" : "https://github.com/powerman/perl-Export-Attrs.git", "web" : "https://github.com/powerman/perl-Export-Attrs" } }, "version" : "v0.1.0", "x_contributors" : [ "Damian Conway ", "Niko Tyni " ] } t000755001750001750 012657417674 15324 5ustar00powermanpowerman000000000000Export-Attrs-v0.1.000.load.t100644001750001750 17312657417674 16767 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0/tuse Test::More tests => 1; BEGIN { use_ok( 'Export::Attrs' ); } diag( "Testing Export::Attrs $Export::Attrs::VERSION" ); 01export.t100644001750001750 27312657417674 17315 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0/tuse Test::More tests => 1; package Lib; use Export::Attrs; sub doit :Export { "Do it!"; } 1; package main; import Lib qw(doit); is(doit(), "Do it!", "function exported as expected"); Export000755001750001750 012657417674 17110 5ustar00powermanpowerman000000000000Export-Attrs-v0.1.0/libAttrs.pm100644001750001750 3015212657417674 20724 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0/lib/Exportpackage Export::Attrs; our $VERSION = 'v0.1.0'; use warnings; use strict; use Carp; use Attribute::Handlers; use PadWalker qw( var_name peek_my ); my %IMPORT_for; sub import { my $caller = caller; no strict 'refs'; *{$caller.'::import'} = \&_generic_import; *{$caller.'::IMPORT'} = sub (&) { $IMPORT_for{$caller} = shift }; for my $var_type (qw( SCALAR ARRAY HASH CODE )) { *{$caller.'::MODIFY_'.$var_type.'_ATTRIBUTES'} = \&_generic_handler; } return; } my %tagsets_for; my %is_exported_from; my %named_tagsets_for; my %decl_loc_for; my %name_of; my $IDENT = '[^\W\d]\w*'; sub _generic_handler { my ($package, $referent, @attrs) = @_; ATTR: for my $attr (@attrs) { ($attr||=q{}) =~ s/\A Export (?: \( (.*) \) )? \z/$1||q{}/exms or next ATTR; my @tagsets = grep {length $_} split m/ \s+,?\s* | ,\s* /xms, $attr; my (undef, $file, $line) = caller(1); $file =~ s{.*/}{}xms; if (my @bad_tags = grep {!m/\A :$IDENT \z/xms} @tagsets) { die 'Bad tagset', (@bad_tags==1?' ':'s '), "in :Export attribute at '$file' line $line: [@bad_tags]\n"; } my $tagsets = $tagsets_for{$package} ||= {}; for my $tagset (@tagsets) { push @{ $tagsets->{$tagset} }, $referent; } push @{ $tagsets->{':ALL'} }, $referent; $is_exported_from{$package}{$referent} = 1; $decl_loc_for{$referent} = "$file line $line"; $name_of{$referent} = _get_lexical_name($referent); undef $attr; } return grep {defined $_} @attrs; } my %desc_for = ( SCALAR => 'lexical scalar variable', ARRAY => 'lexical array variable', HASH => 'lexical hash variable', CODE => 'anonymous subroutine', ); my %hint_for = ( SCALAR => "(declare the variable with 'our' instead of 'my')", ARRAY => "(declare the variable with 'our' instead of 'my')", HASH => "(declare the variable with 'our' instead of 'my')", CODE => "(specify a name after the 'sub' keyword)", ); sub _get_lexical_name { my ($var_ref) = @_; return if ref $var_ref eq 'CODE'; SEARCH: for my $up_level (1..(~0>>1)-1) { my $sym_tab_ref = eval { peek_my($up_level) } or last SEARCH; for my $var_name (keys %{$sym_tab_ref}) { return $var_name if $var_ref == $sym_tab_ref->{$var_name}; } } return; } sub _invert_tagset { my ($package, $tagset) = @_; my %inverted_tagset; for my $tag (keys %{$tagset}) { for my $sub_ref (@{$tagset->{$tag}}) { my $type = ref $sub_ref; my $sym = Attribute::Handlers::findsym($package, $sub_ref, $type) || $name_of{$sub_ref} or die "Can't export $desc_for{$type} ", "at $decl_loc_for{$sub_ref}\n$hint_for{$type}\n"; if (ref $sym) { $sym = *{$sym}{NAME}; } $inverted_tagset{$tag}{$sym} = $sub_ref; } } return \%inverted_tagset; } my %type_for = qw( $ SCALAR @ ARRAY % HASH ); # Reusable import() subroutine for all packages... sub _generic_import { my $package = shift; my $tagset = $named_tagsets_for{$package} ||= _invert_tagset($package, $tagsets_for{$package}); my $is_exported = $is_exported_from{$package}; my $errors; my %request; my $subs_ref; my $args_supplied = @_; my $argno = 0; REQUEST: while ($argno < @_) { my $request = $_[$argno]; if (my ($sub_name) = $request =~ m/\A &? ($IDENT) (?:\(\))? \z/xms) { if (exists $request{$sub_name}) { splice @_, $argno, 1; next REQUEST; } no strict 'refs'; no warnings 'once'; if (my $sub_ref = *{$package.'::'.$sub_name}{CODE}) { if ($is_exported->{$sub_ref}) { $request{$sub_name} = $sub_ref; splice @_, $argno, 1; next REQUEST; } } } elsif (my ($sigil, $name) = $request =~ m/\A ([\$\@%])($IDENT) \z/xms) { next REQUEST if exists $request{$sigil.$name}; no strict 'refs'; no warnings 'once'; if (my $var_ref = *{$package.'::'.$name}{$type_for{$sigil}}) { if ($is_exported->{$var_ref}) { $request{$sigil.$name} = $var_ref; splice @_, $argno, 1; next REQUEST; } } } elsif ($request =~ m/\A :$IDENT \z/xms and $subs_ref = $tagset->{$request}) { @request{keys %{$subs_ref}} = values %{$subs_ref}; splice @_, $argno, 1; next REQUEST; } $errors .= " $request"; $argno++; } # Report unexportable requests... my $real_import = $IMPORT_for{$package}; croak "$package does not export:$errors\nuse $package failed" if $errors && !$real_import; if (!$args_supplied) { %request = %{$tagset->{':DEFAULT'}||={}} } my $mandatory = $tagset->{':MANDATORY'} ||= {}; @request{ keys %{$mandatory} } = values %{$mandatory}; my $caller = caller; for my $sub_name (keys %request) { no strict 'refs'; my ($sym_name) = $sub_name =~ m{\A [\$\@&%]? (.*)}xms; *{$caller.'::'.$sym_name} = $request{$sub_name}; } if ($real_import) { my $idx=0; while ($idx < @_) { if (defined $_[$idx]) { $idx++ } else { splice @_, $idx, 1 } } goto &{$real_import}; } return; } 1; # Magic true value required at end of module __END__ =encoding utf8 =head1 NAME Export::Attrs - The Perl 6 'is export(...)' trait as a Perl 5 attribute =head1 VERSION This document describes Export::Attrs version v0.1.0 =head1 SYNOPSIS package Some::Module; use Export::Attrs; # Export &foo by default, when explicitly requested, # or when the ':ALL' export set is requested... sub foo :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 :Export(:DEFAULT :bees :pubs) { print "baaa!"; } # Export &baz when explicitly requested # or when the ':bees' or ':ALL' export set is requested... sub baz :Export(:bees) { print "baassss!"; } # Always export &qux # (no matter what else is explicitly or implicitly requested) sub qux :Export(:MANDATORY) { print "quuuuuuuuux!"; } # Allow the constant $PI to be exported when requested... use Readonly; Readonly our $PI :Export => 355/113; # Allow the variable $EPSILON to be always exported... our $EPSILON :Export( :MANDATORY ) = 0.00001; sub IMPORT { # This subroutine is called when the module is used (as usual), # but it is called after any export requests have been handled. }; =head1 DESCRIPTION B This module is a fork of L created to restore compatibility with Perl6::Export::Attrs version 0.0.3. Implements a Perl 5 native version of what the Perl 6 symbol export mechanism will look like (with some unavoidable restrictions). It's very straightforward: =over =item * If you want a subroutine or package variable to be capable of being exported (when explicitly requested in the C arguments), you mark it with the C<:Export> attribute. =item * If you want a subroutine or package variable to be automatically exported when the module is used (without specific overriding arguments), you mark it with the C<:Export(:DEFAULT)> attribute. =item * If you want a subroutine or package variable to be automatically exported when the module is used (even if the user specifies overriding arguments), you mark it with the C<:Export(:MANDATORY)> attribute. =item * If the subroutine or package variable should also be exported when particular export groups are requested, you add the names of those export groups to the attribute's argument list. =back That's it. =head2 C blocks Perl 6 replaces the C subroutine with an C block. It's analogous to a C or C block, except that it's executed every time the corresponding module is C'd. The C block is passed the argument list that was specified on the C line that loaded the corresponding module, minus the arguments that were used to specify exports. Note that, due to limitations in Perl 5, the C block provided by this module must be terminated by a semi-colon, unless it is the last statement in the file. =head1 DIAGNOSTICS =over =item %s does not export: %s\nuse %s failed You tried to import the specified subroutine or package variable, but the module didn't export it. Often caused by a misspelling, or forgetting to add an C<:Export> attribute to the definition of the subroutine or variable in question. =item Bad tagset in :Export attribute at %s line %s: [%s] You tried to import a collection of items via a tagset, but the module didn't export any subroutines under that tagset. Is the tagset name misspelled (maybe you forgot the colon?). =item Can't export lexical %s variable at %s The module can only export package variables. You applied the C<:Export> marker to a non-package variable (almost certainly to a lexical). Change the variable's C declarator to an C. =item Can't export anonymous subroutine at %s Although you I apply the C<:Export> marker to an anonymous subroutine, it rarely makes any sense to do so, since that subroutine can't be exported without a name to export it as. Either give the subroutine a name, or make sure it's aliased to a named typeglob at compile-time (or, at least, before it's exported). =back =head1 CONFIGURATION AND ENVIRONMENT Export::Attrs requires no configuration files or environment variables. =head1 DEPENDENCIES This module requires the Attribute::Handlers module to handle the attributes. =head1 INCOMPATIBILITIES This module cannot be used with the Memoize CPAN module, because memoization replaces the original subroutine with a wrapper. Because the C<:Export> attribute is applied to the original (not the wrapper), the memoized wrapper is not found by the exporter mechanism. =head1 LIMITATIONS Note that the module does not support exporting lexical variables, since there is no way for the exporter mechanism to determine the name of a lexical and hence to export it. Nor does this module support the numerous addition export modes that Perl 6 offers, such as export-as-lexical or export-as-state. =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. Feel free to fork the repository and submit pull requests. L git clone https://github.com/powerman/perl-Export-Attrs.git =head2 Resources =over =item * MetaCPAN Search L =item * CPAN Ratings L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Testers Matrix L =item * CPANTS: A CPAN Testing Service (Kwalitee) L =back =head1 AUTHOR Alex Efros Epowerman@cpan.orgE Damian Conway EDCONWAY@cpan.orgE =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2016 by Alex Efros Epowerman@cpan.orgE. Copyright (c) 2005,2015 Damian Conway EDCONWAY@cpan.orgE. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut author-pod-syntax.t100644001750001750 50312657417674 21235 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0/t#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); release-distribution.t100644001750001750 70312657417674 21766 0ustar00powermanpowerman000000000000Export-Attrs-v0.1.0/t BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval 'require Test::Distribution'; plan( skip_all => 'Test::Distribution not installed' ) if $@; Test::Distribution->import( podcoveropts => { # also_private => [ # qr/^(?:IMPORT)$/, # ], # pod_from => 'MAIN PM FILE HERE', } );