Exporter-Lite-0.08/000755 000765 000024 00000000000 12645523605 014410 5ustar00neilbstaff000000 000000 Exporter-Lite-0.08/Changes000644 000765 000024 00000003331 12645523215 015700 0ustar00neilbstaff000000 000000 Revision history for Perl module Exporter::Lite 0.08 2016-01-13 - Fixed typo in name of Constant::Export::Lazy in SEE ALSO. MANWAR++ - Simplified Makefile.PL 0.07 2015-10-09 - Updated github repo URL after changing my github username 0.06 2014-07-29 - Improved the abstract - explicit mention that functions are supported - Improved the SYNOPSIS - split into separate code blocks - Improved the DESCRIPTION. Made clearer that as soon as you specify an import symbol, you have to also specify any you want from @EXPORT. - Removed the BUGS and CAVEATS section from the doc; it was just being self-deprecating about whether it deserved the "lite" moniker. 0.05 2014-03-26 - Improved the DESCRIPTION section, particularly the first paragraph. - Added a bunch more Exporter modules to the SEE ALSO section. 0.04 2014-03-26 - Added Constant::Exporter::Lazy to SEE ALSO - Had forgotten to put README and Changes in MANIFEST. Sigh. 0.03 2014-03-25 - Now maintained by NEILB - Fixed typo reported by dsteinbrunner in RT#87096 - Now use strict and warnings - Added github repo to metadata and pod - Added README - Specified min perl version 5.6.0 in metadata - Set PREREQ_PM, TEST_REQUIRES, CONFIGURE_REQUIRES in Makefile.PL - Added a load of modules to SEE ALSO. 0.02_01 2014-03-24 - All but the final bullet in 0.03 were first done in this dev release 0.02 Sat Nov 11 18:09:19 CST 2006 - Added a Changes file. :) - Added a license notice. (jjore@cpan.org) [rt.cpan.org 20323] - Fixed the version check test for 5.10. [rt.cpan.org 13648] - Now depending on Test::More rather than shipping it. 0.01 Sat Dec 16 2001 - First working release Exporter-Lite-0.08/lib/000755 000765 000024 00000000000 12645523605 015156 5ustar00neilbstaff000000 000000 Exporter-Lite-0.08/Makefile.PL000644 000765 000024 00000002407 12645523205 016361 0ustar00neilbstaff000000 000000 #!/usr/bin/perl -w use ExtUtils::MakeMaker; my $mm_ver = $ExtUtils::MakeMaker::VERSION; if ($mm_ver =~ /_/) { $mm_ver = eval $mm_ver; die $@ if $@; } WriteMakefile( NAME => 'Exporter::Lite', VERSION_FROM => "lib/Exporter/Lite.pm", PREREQ_PM => { 'strict' => 0, 'warnings' => 0, 'Carp' => 0, }, ($mm_ver >= 6.64 ? (TEST_REQUIRES => { 'Test::More' => '0.34', }) : () ), ($mm_ver >= 6.52 ? (CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => 6.30, }) : () ), ($mm_ver >= 6.31 ? (LICENSE => 'perl') : () ), ($mm_ver >= 6.48 ? (MIN_PERL_VERSION => 5.006) : () ), ($mm_ver <= 6.45 ? () : (META_MERGE => { 'meta-spec' => { version => 2 }, resources => { bugtracker => 'http://rt.cpan.org/Public/Dist/Display.html?Name=Exporter-Lite', repository => { type => 'git', web => 'https://github.com/neilb/Exporter-Lite', url => 'https://github.com/neilb/Exporter-Lite.git', }, }, }) ), ); Exporter-Lite-0.08/MANIFEST000644 000765 000024 00000000402 12645523605 015535 0ustar00neilbstaff000000 000000 Changes MANIFEST Makefile.PL README lib/Exporter/Lite.pm t/Exporter-Lite.t t/lib/Dummy.pm META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Exporter-Lite-0.08/META.json000644 000765 000024 00000002367 12645523605 016041 0ustar00neilbstaff000000 000000 { "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.02, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Exporter-Lite", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.3" } }, "runtime" : { "requires" : { "Carp" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.34" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/neilb/Exporter-Lite.git", "web" : "https://github.com/neilb/Exporter-Lite" } }, "version" : "0.08", "x_serialization_backend" : "JSON::PP version 2.27203" } Exporter-Lite-0.08/META.yml000644 000765 000024 00000001176 12645523605 015666 0ustar00neilbstaff000000 000000 --- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: '0' Test::More: '0.34' configure_requires: ExtUtils::MakeMaker: '6.3' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.02, 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: Exporter-Lite no_index: directory: - t - inc requires: Carp: '0' perl: '5.006' strict: '0' warnings: '0' resources: repository: https://github.com/neilb/Exporter-Lite.git version: '0.08' x_serialization_backend: 'CPAN::Meta::YAML version 0.016' Exporter-Lite-0.08/README000644 000765 000024 00000001120 12314124306 015246 0ustar00neilbstaff000000 000000 README for Perl module Exporter::Lite This module is a lightweight version of the core Exporter module, providing a subset of that module's functionality. You can read a nicely formatted version of the documentation for this module online: https://metacpan.org/pod/Exporter::Lite You should be able to install this using your usual method for installing modules from CPAN. If you don't have a usual method yet, have a look at: http://www.cpan.org/modules/INSTALL.html This module was written by Michael G Schwern. It is now being maintained by Neil Bowers Exporter-Lite-0.08/t/000755 000765 000024 00000000000 12645523605 014653 5ustar00neilbstaff000000 000000 Exporter-Lite-0.08/t/Exporter-Lite.t000644 000765 000024 00000005015 12314073406 017534 0ustar00neilbstaff000000 000000 #!/usr/bin/perl -w use lib qw(t/lib); use Test::More tests => 30; BEGIN { use_ok('Exporter::Lite'); } can_ok(__PACKAGE__, 'import'); { package Test1; use Dummy; ::can_ok('Dummy', 'import'); ::ok( defined &foo, '@EXPORT' ); ::is( foo, 42, ' in one piece' ); ::is( $foo, 'foofer', ' and variables' ); } { package YATest1; use Dummy qw(foo); ::ok( defined &foo, '@EXPORT with explicit request' ); ::is( foo, 42, ' in one piece' ); } { package Test2; use Dummy (); ::ok( !defined &foo, 'import with ()' ); } { package Test3; eval { Dummy->import('car') }; ::like( $@, '/"car" is not exported by the Dummy module/', 'importing non-expoted function' ); } { package Test4; use Dummy qw(bar); ::ok( defined &bar, '@EXPORT_OK' ); ::ok( !defined &foo, ' overrides @EXPORT' ); ::ok( !defined &my_sum, ' only what we asked for from @EXPORT_OK' ); ::is( bar, 23, ' not damaged in transport' ); } { package YATest4; use Dummy qw(bar $bar); ::ok( defined &bar, '@EXPORT_OK' ); ::ok( !defined &foo, ' overrides @EXPORT' ); ::ok( !defined &my_sum, ' only what we asked for from @EXPORT_OK' ); ::is( bar, 23, ' not damaged in transport' ); ::is( $bar, 'barfer', ' $bar exported' ); } { package Test5; my $warning = ''; local $SIG{__WARN__} = sub { $warning = join '', @_ }; eval 'use Dummy qw(bar)'; eval 'use Dummy qw(&bar)'; ::ok( defined &bar, 'importing multiple times' ); ::is( $@, '', ' no errors' ); ::is( $warning, '', ' no warnings' ); } { package Test6; my $warning = ''; local $SIG{__WARN__} = sub { $warning = join '', @_ }; eval 'use Dummy qw(bar &bar bar bar &bar bar)'; ::ok( defined &bar, 'importing duplicates' ); ::is( $@, '', ' no errors' ); ::is( $warning, '', ' no warnings' ); } { package Test7; use Dummy qw(my_sum bar foo); ::is( prototype("Dummy::my_sum"), '&@', 'imported sub has prototype' ); ::is( prototype("my_sum"), '&@', ' prototype preserved' ); my @list = qw(1 2 3 4); my $sum = my_sum { $_[0] + $_[1] } @list; ::is( $sum, 10, ' and it works' ); } { package Test8; eval "use Dummy 0.5"; ::is( $@, '', 'use Foo VERSION' ); eval "use Dummy 99"; ::like( $@, '/Dummy version 99.* required/', 'use with version check' ); } Exporter-Lite-0.08/t/lib/000755 000765 000024 00000000000 12645523605 015421 5ustar00neilbstaff000000 000000 Exporter-Lite-0.08/t/lib/Dummy.pm000644 000765 000024 00000000527 12314073406 017046 0ustar00neilbstaff000000 000000 package Dummy; use Exporter::Lite; @EXPORT = qw(&foo $foo); @EXPORT_OK = qw(&bar my_sum $bar); $VERSION = 0.5; $foo = 'foofer'; sub foo { 42 } $bar = 'barfer'; sub bar { 23 } sub my_sum (&@) { my($sub, @list) = @_; foreach (@list) { $sum = $sub->($_, $sum || 0); } return $sum; } sub car { "yarblockos" } return 23; Exporter-Lite-0.08/lib/Exporter/000755 000765 000024 00000000000 12645523605 016766 5ustar00neilbstaff000000 000000 Exporter-Lite-0.08/lib/Exporter/Lite.pm000644 000765 000024 00000016143 12645523413 020223 0ustar00neilbstaff000000 000000 package Exporter::Lite; require 5.006; use warnings; use strict; our $VERSION = '0.08'; our @EXPORT = qw(import); sub import { my($exporter, @imports) = @_; my($caller, $file, $line) = caller; no strict 'refs'; unless( @imports ) { # Default import. @imports = @{$exporter.'::EXPORT'}; } else { # Because @EXPORT_OK = () would indicate that nothing is # to be exported, we cannot simply check the length of @EXPORT_OK. # We must to oddness to see if the variable exists at all as # well as avoid autovivification. # XXX idea stolen from base.pm, this might be all unnecessary my $eokglob; if( $eokglob = ${$exporter.'::'}{EXPORT_OK} and *$eokglob{ARRAY} ) { if( @{$exporter.'::EXPORT_OK'} ) { # This can also be cached. my %ok = map { s/^&//; $_ => 1 } @{$exporter.'::EXPORT_OK'}, @{$exporter.'::EXPORT'}; my($denied) = grep {s/^&//; !$ok{$_}} @imports; _not_exported($denied, $exporter, $file, $line) if $denied; } else { # We don't export anything. _not_exported($imports[0], $exporter, $file, $line); } } } _export($caller, $exporter, @imports); } sub _export { my($caller, $exporter, @imports) = @_; no strict 'refs'; # Stole this from Exporter::Heavy. I'm sure it can be written better # but I'm lazy at the moment. foreach my $sym (@imports) { # shortcut for the common case of no type character (*{$caller.'::'.$sym} = \&{$exporter.'::'.$sym}, next) unless $sym =~ s/^(\W)//; my $type = $1; my $caller_sym = $caller.'::'.$sym; my $export_sym = $exporter.'::'.$sym; *{$caller_sym} = $type eq '&' ? \&{$export_sym} : $type eq '$' ? \${$export_sym} : $type eq '@' ? \@{$export_sym} : $type eq '%' ? \%{$export_sym} : $type eq '*' ? *{$export_sym} : do { require Carp; Carp::croak("Can't export symbol: $type$sym") }; } } #"# sub _not_exported { my($thing, $exporter, $file, $line) = @_; die sprintf qq|"%s" is not exported by the %s module at %s line %d\n|, $thing, $exporter, $file, $line; } 1; __END__ =head1 NAME Exporter::Lite - lightweight exporting of functions and variables =head1 SYNOPSIS package Foo; use Exporter::Lite; our @EXPORT = qw($This That); # default exports our @EXPORT_OK = qw(@Left %Right); # optional exports Then in code using the module: use Foo; # $This and &That are imported here You have to explicitly ask for optional exports: use Foo qw/ @Left %Right /; =head1 DESCRIPTION Exporter::Lite is an alternative to L, intended to provide a lightweight subset of the most commonly-used functionality. It supports C, C<@EXPORT> and C<@EXPORT_OK> and not a whole lot else. Unlike Exporter, it is not necessary to inherit from Exporter::Lite; Ie you don't need to write: @ISA = qw(Exporter::Lite); Exporter::Lite simply exports its import() function into your namespace. This might be called a "mix-in" or a "role". Setting up a module to export its variables and functions is simple: package My::Module; use Exporter::Lite; our @EXPORT = qw($Foo bar); Functions and variables listed in the C<@EXPORT> package variable are automatically exported if you use the module and don't explicitly list any imports. Now, when you C, C<$Foo> and C will show up. Optional exports are listed in the C<@EXPORT_OK> package variable: package My::Module; use Exporter::Lite; our @EXPORT_OK = qw($Foo bar); When My::Module is used, C<$Foo> and C will I show up, unless you explicitly ask for them: use My::Module qw($Foo bar); Note that when you specify one or more functions or variables to import, then you must also explicitly list any of the default symbols you want to use. So if you have an exporting module: package Games; our @EXPORT = qw/ pacman defender /; our @EXPORT_OK = qw/ galaga centipede /; Then if you want to use both C and C, then you'd write: use Games qw/ pacman galaga /; =head1 Methods Export::Lite has one public method, import(), which is called automatically when your modules is use()'d. In normal usage you don't have to worry about this at all. =over 4 =item B Some::Module->import; Some::Module->import(@symbols); Works just like C excepting it only honors @Some::Module::EXPORT and @Some::Module::EXPORT_OK. The given @symbols are exported to the current package provided they are in @Some::Module::EXPORT or @Some::Module::EXPORT_OK. Otherwise an exception is thrown (ie. the program dies). If @symbols is not given, everything in @Some::Module::EXPORT is exported. =back =head1 DIAGNOSTICS =over 4 =item '"%s" is not exported by the %s module' Attempted to import a symbol which is not in @EXPORT or @EXPORT_OK. =item 'Can\'t export symbol: %s' Attempted to import a symbol of an unknown type (ie. the leading $@% salad wasn't recognized). =back =head1 SEE ALSO L is the grandaddy of all Exporter modules, and bundled with Perl itself, unlike the rest of the modules listed here. L defines attributes which you use to mark which subs and variables you want to export, and how. L also uses attributes to control the export of functions and variables from your module. L makes it easy to create a module that exports constants. L is another module that makes it easy to create modules that define and export constants. L is a "sophisticated exporter for custom-built routines"; it lets you provide generators that can be used to customise what gets imported when someone uses your module. L provides the same features as L, but relying only on core dependencies. L is a shortcut for L that provides a more concise notation for providing optional exports. L provides syntactic sugar to make the export status of your functions part of their declaration. Kind of. L lets you export part of an L-based configuration. L lets you export lexical subs from your module. L lets you write a module that exports function-style constants, which are instantiated lazily. L will export everything from your module that it thinks is a public function (name doesn't start with an underscore). L lets you export class methods as regular subroutines. L is like Exporter, but with persistent defaults and auto-ISA. =head1 REPOSITORY L =head1 AUTHORS Michael G Schwern =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F =cut