PaxHeader/load-0.26000755 000765 000024 00000000210 15001425530 015052 xustar00lnationstaff000000 000000 30 mtime=1745234776.839037853 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/000755 000765 000024 00000000000 15001425530 013162 5ustar00lnationstaff000000 000000 load-0.26/PaxHeader/CHANGELOG000644 000765 000024 00000000335 13561555031 016357 xustar00lnationstaff000000 000000 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmIxOTs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b19;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/CHANGELOG000644 000765 000024 00000017314 13561555031 014413 0ustar00lnationstaff000000 000000 0.24 9 November 2019 Adoption. 0.23 24 May 2012 Added license information. Verified it works with 5.16.0, threaded and unthreaded. 0.22 13 April 2012 Fixed spelling error as suggested by Gregor Herrmann. RT #76532 0.21 31 March 2012 Fixed some pod issues. Brought code in line with current esthetics. Changed internal storage from packed L3 to packed w3 format, for hopefully smaller memory footprint. 0.20 20 September 2010 Fixed problem that started to manifest itself with a slightly different handling of localized $@, starting in perl 5.13.x. 0.19 24 April 2007 Fixed problem in test-suite that was long overseen because it would work ok if load.pm was already installed (which it was on my dev system). Not sure whether this was internally introduced, or some new feature of Test::More. 0.18 18 October 2005 Added fix for missing Kwalitee point for not using 'strict' 0.17 9 July 2005 Finished AutoLoader emulation mode and adapted testing accordingly. Fixed some test problems if ifdef.pm is not installed. Changes tests so that the first failure will die with a dump so that specific problems can be worked on more precisely. Verified load.pm works on Perl 5.8.7. 30 September 2004 Added initial support AutoLoader emulation mode. Verified load.pm will work on Perl 5.8.5. 0.16 15 March 2004 Changed tracing calls so that they get optimized away if tracing is not active. Fixed bug that would cause "ifdef.pm" to split on every character if "now" loading was selected. Fixed bug with subs that really do not exist. Added some more test with regards to the interface with "ifdef.pm". 0.15 14 March 2004 Added support for "ifdef.pm". If ifdef.pm is loaded, then all eval's will be done using the source filter provided by ifdef, possibly activating code depending on environment variables being set. Added tests to check functionality when ifdef.pm is loaded. Fixed some possible minor problems with localizing $_: it appears a simple "local $_" is not enough, instead a "local $_ = \my $foo" seems to be the canonical solution to this problem as of now according to p5p. 28 January 2004 Made sure the test-suite cleans up on multi-versioned systems. 0.14 28 December 2003 Added automatic required modules update using Devel::Required. 0.13 12 November 2003 Perl 5.8.2 does not handle empty subroutines (sub foo {}) very well. In some cases, it segfaults. This happened in the test-suite. Test-suite has been adapted (that really is the only change, apart from the version number). 0.12 29 September 2003 Added support for register additional "use" modules for specific packages (e.g. when subroutines need to be handled by a source filter). Tests to be added later, if ever here. 26 September 2003 Realised testing for running under taint was pretty trivial: the entire test-suite now runs twice: once with and once without tainting. 0.11 26 September 2003 Turns out load.pm didn't work when taint was active. And it silently failed to boot. This should now be fixed. Added a todo to make tests that will functioning under taint: activating taint in the tests caused too many failures to allow checking in the allotted time.. 0.10 18 September 2003 Frank Tolstrup pointed out some test misses because of CRLF versus LF issues on Windows. These should now also be fixed. Mention Frank in the new ACKNOWLEDGEMENTS section of load. Added thread indicator to trace if threads are used. This should facilitate debugging of the Thread::xxx modules. Added tests for it as well. For the trace to properly detect threads, the threads module must have been loaded prior to loading load.pm. 17 September 2003 Hmmm... I may be taking the "release soon, release often" too literally. Anyway, Frank Tolstrup's output of the failing test-suite under Windows, pointed to a possible seek() problem under Windows. Added a binmode() in case the source-file is opened again for on-demand loading of a subroutine. And the tests with $Foo::{} also failed under Windows: they shouldn't anymore. Installed experimental trace possibility that is activated by setting the environment variable "LOAD_TRACE" to a true value. This is still experimental so therefore only documented here. 0.09 17 September 2003 Frank Tolstrup pointed out that many of the tests wouldn't run under Windows because of quoting issues. Adapted the test so that would not be an issue anymore. Hope this is the last one of today ;-) 0.08 17 September 2003 Indeed, it is one of those days. Added some more tests to make sure that subroutines are indeed loaded on demand. 0.07 17 September 2003 Argh. I guess it is one of those days. Using strict in load.pm bleeds into the eval's and causes compile errors. And of course the test-suite didn't catch it. Removed stricture but added a comment in the source about it. Adapted the test-suite so it _will_ catch it this time (but won't of course, because it's fixed). 0.06 17 September 2003 Finally figured how to make something like a test-suite. Now checks whether ondemand subs can be called and whether or not they exist and can be can()ned. Argh. A typo caused the "now" functionality to completely broken. This is now fixed. Problem was introduced in version 0.02. Added optional support for strict and warnings in the source. 11 August 2003 Fixed stupid typo in Makefile.PL that caused description of module not to be included ever. Verified load.pm will work on Perl 5.8.1. 0.05 29 December 2002 Increased version to be able to upload a more recent version of load.pm to CPAN to prevent interference with Jos 'Kane' Boumans' version of load.pm. 0.04 21 October 2002 Fixed small problem when running with warnings and attempting to access non-existing subroutine. Spotted by Lars Fenneberg. 0.03 1 October 2002 Changed using of lexical file handles to globs, to ensure compatibility with earlier versions of Perl. Fixed problem with running with warnings (caused by UNIVERSAL::can redefine). Removed use strict and other stuff to make this module yet leaner and meaner. 0.02 30 September 2002 Now hijacks UNIVERSAL::can so that ->can does the right thing for subroutines that have not been loaded yet. As a side effect, this loads the subroutine specified. Added documentation to reflect that. Localised $_, $! and $@ at several places just to make sure they don't clobber anything on the outside. Added support for line numbers and file name (swiped from AutoSplit generated code), so that eval errors will give you more information. Added check for DESTROY: apparently you get an infinite loop if you're gotoing the DESTROY if it doesn't exist. Now AUTOLOAD just returns for DESTROY if it doesn't exist. Fixed typo in _scan() which would trigger a loop if a second __END__ was encountered in the source of a module. 0.01 29 September 2002 First version of load.pm, renamed from jit.pm after discussions on and off p5p. load-0.26/PaxHeader/MANIFEST000644 000765 000024 00000000152 11757477257 016315 xustar00lnationstaff000000 000000 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/MANIFEST000644 000765 000024 00000000355 11757477257 014351 0ustar00lnationstaff000000 000000 MANIFEST CHANGELOG README TODO VERSION Makefile.PL lib/load.pm t/load01.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) load-0.26/PaxHeader/t000755 000765 000024 00000000210 15001425530 015315 xustar00lnationstaff000000 000000 30 mtime=1745234776.742836472 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/t/000755 000765 000024 00000000000 15001425530 013425 5ustar00lnationstaff000000 000000 load-0.26/PaxHeader/README000644 000765 000024 00000000335 11757476774 016052 xustar00lnationstaff000000 000000 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmIxOTs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b19;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/README000644 000765 000024 00000001044 11757476774 014077 0ustar00lnationstaff000000 000000 README for load The load.pm allows you to have Perl load subroutines only when necessary. It is primarily intended as a memory saving action, specifically for threaded Perl and mod_perl applications, but maybe useful in more traditional Perl applications as well. Copyright (c) 2002-2007 Elizabeth Mattijsen . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Version: 0.23 Required Modules: (none) perl Makefile.PL make make test make install load-0.26/PaxHeader/TODO000644 000765 000024 00000000335 10050423664 015631 xustar00lnationstaff000000 000000 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmIxOTs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b19;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/TODO000644 000765 000024 00000000237 10050423664 013661 0ustar00lnationstaff000000 000000 Use the handle if there is one available. Use a source-filter to implement a ":ondemand" attribute. Add more testing for interaction with "ifdef.pm". load-0.26/PaxHeader/VERSION000644 000765 000024 00000000335 11445660165 016221 xustar00lnationstaff000000 000000 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmIxOTs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b19;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/VERSION000644 000765 000024 00000000005 11445660165 014242 0ustar00lnationstaff000000 000000 0.20 load-0.26/PaxHeader/META.yml000644 000765 000024 00000000210 15001425530 016375 xustar00lnationstaff000000 000000 30 mtime=1745234776.781427165 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/META.yml000644 000765 000024 00000001053 15001425530 014432 0ustar00lnationstaff000000 000000 --- abstract: 'load - control when subroutines will be loaded' author: - 'Elizabeth Mattijsen (liz@dijkmat.nl)' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: load no_index: directory: - t - inc requires: {} version: '0.26' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' load-0.26/PaxHeader/lib000755 000765 000024 00000000210 15001425530 015620 xustar00lnationstaff000000 000000 30 mtime=1745234776.743325803 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/lib/000755 000765 000024 00000000000 15001425530 013730 5ustar00lnationstaff000000 000000 load-0.26/PaxHeader/Makefile.PL000644 000765 000024 00000000335 11757476672 017141 xustar00lnationstaff000000 000000 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmIxOTs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b19;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/Makefile.PL000644 000765 000024 00000000523 11757476672 015167 0ustar00lnationstaff000000 000000 require 5.000; use ExtUtils::MakeMaker; eval "use Devel::Required"; WriteMakefile ( NAME => "load", ($] < 5.005) ? () : ( AUTHOR => 'Elizabeth Mattijsen (liz@dijkmat.nl)', ABSTRACT => 'load - control when subroutines will be loaded'), VERSION_FROM => 'lib/load.pm', LICENSE => 'perl', PREREQ_PM => { }, ); load-0.26/PaxHeader/META.json000644 000765 000024 00000000210 15001425530 016545 xustar00lnationstaff000000 000000 30 mtime=1745234776.838075649 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/META.json000644 000765 000024 00000001607 15001425530 014607 0ustar00lnationstaff000000 000000 { "abstract" : "load - control when subroutines will be loaded", "author" : [ "Elizabeth Mattijsen (liz@dijkmat.nl)" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "load", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : {} } }, "release_status" : "stable", "version" : "0.26", "x_serialization_backend" : "JSON::PP version 4.16" } load-0.26/lib/PaxHeader/load.pm000644 000765 000024 00000000372 15001425520 017157 xustar00lnationstaff000000 000000 29 mtime=1745234768.78785396 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmI1MDs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b50;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/lib/load.pm000644 000765 000024 00000073162 15001425520 015215 0ustar00lnationstaff000000 000000 package load; $VERSION= '0.26'; #------------------------------------------------------------------------------- # No, we're NOT using strict here. There are several reasons, the most # important being that strict bleeds into the string eval's that load.pm # is doing, causing compilation errors in all but the most simple modules. # If you _do_ want stricture as a developer of load.pm, simply de-activate # the lines of the BEGIN block below here #------------------------------------------------------------------------------- BEGIN { # We're fooling the Kwalitee checker into thinking we're strict use strict; } # do this at compile time my $now; BEGIN { # make sure we have warnings or dummy warnings for older Perl's eval { require warnings } or do { $INC{'warnings.pm'} = '' }; # set flag indicating whether everything should be loaded immediately $now= $ENV{'LOAD_NOW'} || 0; # environment var undocumented for now # "ifdef" is loaded, can we use it? if (defined $ifdef::VERSION) { die "Must have 'ifdef' version 0.07 or higher to handle on demand loading\n" if $ifdef::VERSION < 0.07; *IFDEF= sub () { 1 }; } # ifdef not loaded else { *IFDEF= sub () { 0 }; } # we're supposed to trace if ($ENV{'LOAD_TRACE'}) { *TRACE= sub () { 1 }; eval <<'EOD'; # only way to ensure it isn't there when we're not tracing sub _trace { my $tid = $threads::VERSION ? ' ['.threads->tid.']' : ''; warn "load$tid: ",$_[0],$/; } #_trace EOD } # we're not supposed to trace else { *TRACE= sub () { 0 }; } # make sure we intercept ->can no warnings 'redefine'; my $can= \&UNIVERSAL::can; *UNIVERSAL::can= sub { &{$can}( @_ ) || (ref( $_[0] ) ? undef : _can( @_ )) }; } #BEGIN # hash with modules that should be used extra, keyed to package my %use; # satisfy -require- 1; #------------------------------------------------------------------------------- # # Class Methods # #------------------------------------------------------------------------------- # IN: 1 class (ignored) # 2 package for which to add additional use-s # 3 additional module to be used sub register { $use{ $_[1] }= ( $use{ $_[1] } || '' ) . "use $_[2];" } #register #------------------------------------------------------------------------------- # # Standard Perl Features # #------------------------------------------------------------------------------- # IN: 1 class (ignored) # 2..N various parameters sub import { my $class = shift; my ($module,undef,$lineno) = caller(); # need to check / handle parameters specified if (@_) { my $inmain= ( $module eq 'main' ); my $autoload= !$inmain; my $scan= 1; my $thisnow= $now; # check each parameter separately foreach (@_) { # handle "now" if ( $_ eq 'now' ) { ( $inmain ? $now= $thisnow : $thisnow )= $scan= 1; } # handle "ondemand" elsif ( $_ eq 'ondemand' ) { ( $inmain ? $now= $thisnow : $thisnow )= 0; $scan= 1; } # want to export AUTOLOAD sub (AUTOLOAD = AutoLoader compatible) elsif ( m#^(?:autoload|AUTOLOAD)$# ) { die "Can not $_ in main namespace" if $inmain; $autoload= 1; } # don't want to scan now elsif ( $_ eq 'dontscan' ) { ( $inmain ? $now= $thisnow : $thisnow )= $scan= 0; } # want to inherit AUTOLOAD elsif ( $_ eq 'inherit' ) { die "Can not inherit in main namespace" if $inmain; $autoload= 0; } # want to enable AutoLoader mode elsif ( $_ eq 'AutoLoader' ) { die "Can only activate AutoLoader emulation mode from script" if !$inmain; # did not emulate AutoLoader before if ( !$INC{'AutoLoader.pm'} or $INC{'AutoLoader.pm'} ne $INC{__PACKAGE__.'.pm' } ) { *AutoLoader::import= \&import; *AutoLoader::AUTOLOAD= \&AUTOLOAD; # mark as loaded now, owned by us $INC{'AutoLoader.pm'}= $INC{__PACKAGE__.'.pm'}; } } # huh? else { die "Don't know how to handle $_"; } } # in a module, scan it if necessary if ( !$inmain ) { _scan( $module, $thisnow ) if $scan; no strict 'refs'; *{$module.'::AUTOLOAD'}= \&AUTOLOAD if $autoload; } } # called from a script / command line, huh? elsif ( $module eq 'main' ) { die "Does not make sense to just 'use $class;' from your script" if $lineno; } # no parameters, scan the source else { _scan( $module ); # export AUTOLOAD if called here if ( $class eq __PACKAGE__ ) { no strict 'refs'; *{$module.'::AUTOLOAD'}= \&AUTOLOAD; } } } #import #------------------------------------------------------------------------------- sub AUTOLOAD { # go execute intended AUTOLOAD if possible $load::AUTOLOAD =~ m#^(.*)::(.*?)$#; goto &{$load::AUTOLOAD} if _can( $1, $2 ); # nothing to do if unknown DESTROY return if $2 eq 'DESTROY'; # huh? my ( $package, $filename, $line )= caller; die "Undefined subroutine &$load::AUTOLOAD called at $filename line $line\n"; } #AUTOLOAD #------------------------------------------------------------------------------- # # Internal Subroutines # #------------------------------------------------------------------------------- # _scan # # Set up / load given module # # IN: 1 module to scan (AAA::BBB) # 2 optional: flag to load everything now sub _scan { my $module= shift; my $loadnow= defined( $_[0] ) ? shift : $now; # make sure we won't clobber sensitive system vars local $_= \my $foo; # make sure $_ is localized properly local( $!, $@ ); # open the file to read my $file= _filename( $module ) or die "Could not find file for '$module'"; open( VERSION, "<$file" ) # use VERSION as glob to save memory or die "Could not open file '$file' for '$module': $!"; binmode VERSION # needed for Windows systems, apparently or die "Could not set binmode on '$file': $!"; # initializations my $line= 0; my $pod= 0; my $package= ''; &ifdef::reset if IFDEF; # should get optimized away if not needed # look through all lines while ( readline VERSION ) { &ifdef::oneline if IFDEF; # should get optimized away if not needed $line++; # inside pod $pod= !m#^=cut#, next if m#^=\w#; next if $pod or m#^\s*\##; # we're done last if m#^__END__#; # not a package next if !m#^package\s+([\w:]+)\s*;#; # found a package die "Found package '$1' after '$package'" if $package; $package= $1; } # huh? die "Could not find package name" if !$package; die "Found package $package inside '$file'" if $package ne $module; # initializations my $endline= $line+1; my $endstart= tell VERSION; # loading now if ($loadnow) { _trace( "now $module, line $endline (offset $endstart, onwards)" ) if TRACE; # load the source my $source= <<"SRC"; package $module; no warnings; #line $endline "$file (loaded now from offset $endstart)" SRC $source .= do { local $/; readline(VERSION) =~ m#^(.*)$#s; $1 }; eval ( IFDEF ? ifdef::process($source) : $source ); die "Error evaluating source: $@" if $@; } # loading on demand else { my $start; my $sub= ''; my $subline; my $length; # process all lines while ( readline VERSION ) { $length= length if IFDEF; &ifdef::oneline if IFDEF; $line++; # inside pod $pod= !m#^=cut#, next if m#^=\w#; next if $pod or m#^\s*\##; # we're done last if m#^__END__#; # huh? die "Only one package per file: found '$1' after '$package'" if m#^package\s+([\w:]+)\s*;#; # not at next sub yet next unless m#^sub\s+([\w:]+)#; # remember where previous sub starts, if any my $seek= tell(VERSION) - ( IFDEF ? $length : length ); _store( $module, $sub, $subline, $start, $seek - $start ) if $sub; # set up for next iteration $sub= $1; die "Cannot handle fully qualified subroutine '$sub'\n" if $sub =~ m#::#; $subline= $line; $start= $seek; } # store rest as a sub, if any _store( $module, $sub, $subline, $start, ( defined() ? tell(VERSION) - length() : -s VERSION ) - $start ) if $sub; } # we're done $load::AUTOLOAD{$module}= undef; close VERSION; return; } #_scan #------------------------------------------------------------------------------- # _filename # # Return filename of module # # IN: 1 module name (AAA::BBB) # OUT: 1 filename (/..../AAA/BBB.pm) or undef if not known sub _filename { # return filename from %INC ( my $key= $_[0] ) =~ s#::#/#g; my $filename= $INC{"$key.pm"}; return $filename if !ref $filename; # return result of call instead return $filename->("$key.pm"); } #_filename #------------------------------------------------------------------------------- # _store # # Store information about subroutine in memory for later usage # # IN: 1 module name # 2 subroutine name (not fully qualified) # 3 line number where sub starts # 4 offset where sub starts # 5 number of bytes to read sub _store { _trace( "store $_[0]::$_[1], line $_[2] (offset $_[3], $_[4] bytes)" ) if TRACE; # huh? eval "package $_[0]; sub $_[1]"; die "Could not create stub: $@\n" if $@; # store the data $load::AUTOLOAD{ $_[0], $_[1] }= pack( 'w3', $_[2], $_[3], $_[4] ) } #_store #------------------------------------------------------------------------------- # _can # # Our version of ->can # # IN: 1 module to load subroutine from # 2 subroutine to load # OUT: 1 reference to subroutine (if exists and loaded, else undef) sub _can { my ( $module, $sub )= @_; # nothing to do here return if $module eq 'main'; # scan file if we need to _scan( $module ) unless exists $load::AUTOLOAD{$module}; # huh? unknown sub? my ( $subline, $start, $length )= unpack( 'w3', $load::AUTOLOAD{ $module, $sub } || '' ); return if !$start; # seek in the file where the source lives local( $!, $@ ); my $file= _filename( $module ) or die "Could not find file for '$module.pm'"; open( VERSION, "<$file" ) # use VERSION glob to conserve memory or die "Could not open file '$file' for '$module.pm': $!"; binmode VERSION # needed for Windows systems, apparently or die "Could not set binmode on '$file': $!"; seek( VERSION, $start, 0 ) or die "Could not seek to $start for $module\::$sub"; # set up evallable pre-amble _trace( "ondemand ${module}::$sub, line $subline (offset $start, $length bytes)" ) if TRACE; my $use= $use{$module} || ''; my $source= <<"SRC"; package $module; no warnings;$use #line $subline "$file (loaded on demand from offset $start for $length bytes)" SRC # get the stuff my $read= read( VERSION, $source, $length, length($source) ); die "Error reading source: only read $read bytes instead of $length" if $read != $length; close VERSION; # initializations &ifdef::reset if IFDEF; # make sure "ifdef" starts afresh my $original= $source; # eval untainted copy $source =~ m#^(.*)$#s; $source= IFDEF ? ifdef::process($1) : $1; eval $source; die "load: $@\n$original====================\n$source" if $@; # done this one delete $load::AUTOLOAD{ $module, $sub }; return \&{ $module . '::' . $sub }; } #_can #------------------------------------------------------------------------------- __END__ =head1 NAME load - control when subroutines will be loaded =head1 SYNOPSIS use load; # default, same as 'autoload' use load 'autoload'; # export AUTOLOAD handler to this namespace use load 'ondemand'; # load subroutines after __END__ when requested, default use load 'now'; # load subroutines after __END__ now use load (); # same as qw(dontscan inherit) use load 'dontscan'; # don't scan module until it is really needed use load 'inherit'; # do NOT export AUTOLOAD handler to this namespace =head1 VERSION This documentation describes version 0.26. =head1 DESCRIPTION The "load" pragma allows a module developer to give the application developer more options with regards to optimize for memory or CPU usage. The "load" pragma gives more control on the moment when subroutines are loaded and start taking up memory. This allows the application developer to optimize for CPU usage (by loading all of a module at compile time and thus reducing the amount of CPU used during the execution of an application). Or allow the application developer to optimize for memory usage, by loading subroutines only when they are actually needed, thereby however increasing the amount of CPU needed during execution. The "load" pragma combines the best of both worlds from L and L. And adds some more features. In a situation where you want to use as little memory as possible, the "load" pragma (in the context of a module) is a drop-in replacement for L. But for situations where you want to have a module load everything it could ever possibly need (e.g. when starting a mod_perl server in pre-fork mode), the "load" pragma can be used (in the context of an application) to have all subroutines of a module loaded without having to make any change to the source of the module in question. So the typical use inside a module is to have: package Your::Module; use load; in the source. And to place all subroutines that you want to be loadable on demand after the (first) __END__. If an application developer decides that all subroutines should be loaded at compile time, (s)he can say in the application: use load 'now'; use Your::Module; This will cause the subroutines of Your::Module to all be loaded at compile time. =head1 MODES OF OPERATION There are basically two places where you can call the "load" pragma: =head2 inside a module When you call the "load" pragma inside a module, you're basically enabling that module for having an external control when certain subroutines will be loaded. As with AutoLoader, any subroutines that should be loaded on demand, should be located B an __END__ line. If no parameters are specified with the C, then the "autoload" parameter is assumed. Whether the module's subroutines are loaded at compile time or on demand, is determined by the calling application. If the application doesn't specify anything specific, the "ondemand" keyword will also be assumed. =head2 inside an application When you call the "load" pragma inside an application, you're basically specifying when subroutines will be loaded by "load" enhanced modules. As an application developer, you can basically use two keywords: "ondemand" and "now". If an application does not call the "load" pragma, the "ondemand" keyword will be assumed. With "ondemand", subroutines will only be loaded when they are actually executed. This saves memory at the expense of extra CPU the first time the subroutine is called. The "now" keyword indicates that all subroutines of all modules that are enhanced with the "load" pragma, will be loaded at compile time (thus using more memory, but B having an extra CPU overhead the first time the subroutine is executed). =head1 KEYWORDS The following keywords are recognized with the C command: =head2 ondemand The "ondemand" keyword indicates that subroutines, of modules that are enhanced with the "load" pragma, will only be loaded when they are actually called. If the "ondemand" keyword is used in the context of an application, all modules that are subsequently Cd, will be forced to load subroutines only when they are actually called (unless the module itself forces a specific setting). If the "ondemand" keyword is used in the context of a module, it indicates that the subroutines of that module, should B be loaded when they are actually needed. Since this takes away the choice from the application developer, the use of the "ondemand" keyword in module context is not encouraged. See also the L and L keywords. =head2 now The "now" keyword indicates that subroutines, of modules that are enhanced with the "load" pragma, will be loaded at compile time. If the "now" keyword is used in the context of an application, all modules that are subsequently Cd, will be forced to load all subroutines at compile time (unless the module forces a specific setting itself). If the "now" keyword is used in the context of a module, it indicates that the subroutines of that module, should B be loaded at compile time. Since this takes away the choice from the application developer, the use of the "now" keyword in module context is not encouraged. See also the L keyword. =head2 dontscan The "dontscan" keyword only makes sense when used in the context of a module. Normally, when a module that is enhanced with the "load" pragma is compiled, the source after the __END__ is scanned for the locations of the subroutines. This makes the compiling of modules a little slower, but allows for a faster (initial) lookup of (yet) unloaded subroutines during execution. If the "dontscan" keyword is specified, this scanning of the source is skipped at compile time. However, as soon as an attempt is made to ececute a subroutine from this module, then first the scanning of the source is performed, before the subroutine in question is loaded. So, you should use the "dontscan" keyword if you are reasonably sure that you will only need subroutines from the module in special cases. In all other cases it will make more sense to have the source scanned at compile time. The "dontscan" keyword will be ignored if an application developer forces subroutines to be loaded at compile time with the L keyword. =head2 autoload The "autoload" keyword only makes sense when used in the context of a module. It indicates that a generic AUTOLOAD subroutine will be exported to the module's namespace. It is selected by default if you use the "load" pragma without parameters in the source of a module. See also the L keyword to B export the generic AUTOLOAD subroutine. =head2 inherit The "inherit" keyword only makes sense when used in the context of a module. It indicates that B AUTOLOAD subroutine will be exported to the module's namespace. This can e.g. be used when you need to have your own AUTOLOAD routine. That AUTOLOAD routine should then contain: $load::AUTOLOAD = $sub; goto &load::AUTOLOAD; to access the "load" pragma functionality. Another case to use the "inherit" keyword would be in a sub-class of a module which also is "load" enhanced. In that case, the inheritance will cause the AUTOLOAD subroutine of the base class to be used, thereby accessing the "load" pragma automagically (and hence the naming of the keyword of course). See also the L keyword to have the module use the generic AUTOLOAD subroutine. =head2 AutoLoader The "AutoLoader" keyword enables AutoLoader emulation mode. It basically takes over the functionality of the AutoLoader module (which is part of Perl's core, and which is used by many of Perl's core modules). Use of AutoLoader emulation mode usually only makes sense in a mod_perl prefork environment (in combination with the "now" keyword), or a threaded Perl environment. It basically adds the flexibility of subroutine loading options of the "load" pragma to the existing codebase of Perl's core and CPAN modules. It is typically invoked from the command line: perl -Mload=AutoLoader or in a mod_perl configuration: use load qw(AutoLoader now); # as early as possible # rest of modules to be loaded The AutoLoader emulation mode has the further advantage for modules being developed with AutoLoader, as it is possible to run the module before having to have installed the module (which is normally a requirement with using AutoLoader). Please note that AutoLoader emulation will only work properly for any modules loaded B the "load" module is loaded. It is therefore important to activate the AutoLoader as soon as possible, before B other modules have been loaded. Of particular interest in this respect are the L and the L modules. =head1 REQUIRED MODULES (none) =head1 DIFFERENCES WITH SIMILAR MODULES There are a number of (core) modules that more or less do the same thing as the "load" pragma. =head2 AutoSplit / AutoLoader The "load" pragma is very similar to the AutoSplit / AutoLoader combination. The main difference is that the splitting takes place when the "load" import is called in a module and that there are no external files created. Instead, just the offsets and lengths are recorded in a hash (when "ondemand" is active) or all the source after __END__ is eval'led (when "now" is active). From a module developer point of view, the advantage is that you do not need to install a module before you can test it. From an application developer point of view, you have the flexibility of having everything loaded now or later (on demand). From a memory usage point of view, the "load" offset/length hash takes up more memory than the equivalent AutoLoader setup. On the other hand, accessing the source of a subroutine may generally be faster because the file is more likely to reside in the operating system's buffers already. As an extra feature, the "load" pragma allows an application to force all subroutines to be loaded at compile time, which is not possible with AutoLoader. The "AutoLoader emulation" mode causes AutoLoader to be replaced by "load", increasing further flexibility in loading options (which can be particularly important in the L<"mod_perl prefork"> situation) and ease of use during development of modules using AutoLoader (as you don't need to install the module before you can test it). =head2 SelfLoader The "load" pragma also has some functionality in common with the SelfLoader module. But it gives more granularity: with SelfLoader, all subroutines that are not loaded directly, will be loaded if B not yet loaded subroutine is requested. It also adds complexities if your module needs to use the handle. So the "load" pragma gives more flexibility and fewer development complexities. And of course, an application can force all subroutines to be loaded at compile time when needed with the "load" pragma. =head1 UNIVERSAL::can To ensure the functioning of the ->can class method and &UNIVERSAL::can, the "load" pragma hijacks the standard UNIVERSAL::can routine so that it can check whether the subroutine/method that you want to check for, actually exists and have a code reference to it returned. This has a side effect that you the subroutine checked for, is loaded. You can use this side effect to load subroutines without calling them. Your::Module->can( 'loadthisnow' ); will load the subroutine "loadthisnow" of the Your::Module module without actually calling it. =head1 CAVEATS Currently you may not have multiple packages in the same file, nor can you have fully qualified subroutine names. The parser that looks for package names and subroutines, is not very smart. This is intentionally so, as making it smarter will make it a lot slower, but probably still not smart enough. Therefore, the C and C's B be at the start of a line. And the name of the C B be on the same line as the C. =head1 EXAMPLES Some code examples. Please note that these are just a part of an actual situation. =head2 base class package Your::Module; use load; Exports the generic AUTOLOAD subroutine and adheres to whatever the application developer specifies as mode of operation. =head2 sub class package Your::Module::Adapted; @ISA = qw(Your::Module); use load (); Does B export the generic AUTOLOAD subroutine, but inherits it from its base class. Also implicitely specifies the "dontscan" keyword, causing the source of the module to be scanned only when the first not yet loaded subroutine is about to be executed. If you only want to have the "inherit" keyword functionality, then you must specify that explicitly: package Your::Module::Adapted; @ISA = qw(Your::Module); use load 'inherit'; =head2 custom AUTOLOAD package Your::Module; use load 'inherit'; sub AUTOLOAD { if (some condition) { $load::AUTOLOAD = $Your::Module::AUTOLOAD; goto &load::AUTOLOAD; } # do your own stuff } If you want to use your own AUTOLOAD subroutine, but still want to use the functionality offered by the "load" pragma, you can use the above construct. =head2 mod_perl prefork use load qw(AutoLoader now); use Your::Module; In pre-fork mod_perl applications (the default mod_perl applications before mod_perl 2.0), it is advantageous to load all possible subroutines when the Apache process is started. This is because the operating system will share memory using a process called "Copy On Write". So even though it will take more memory initially, that memory loss is easily evened out by the gains of having everything shared. Loading a not yet loaded subroutine in that situation, will cause otherwise shared memory to become unshared. Thereby increasing the overall memory usage, because the amount that becomes unshared is typically a lot more than the extra memory used by the subroutine (which is caused by fragmentation of allocated memory). The B emulation mode causes all modules that use C to be handled by C. In combination with the "now" mode, this means that many system modules will also be loaded completely at server startup (causing a grow in initial use of memory, but sharing more memory means that overall memory usage is significantly reduced. =head2 threaded applications and mod_perl worker use Your::Module; Threaded Perl applications, of which mod_perl applications using the "worker" module are a special case, function best when subroutines are only loaded when they are actually needed. This is caused by the nature of the threading model of Perl, in which all data-structures are B to each thread (essentially forcing them to become unshared as far as the operating system is concerned). Benchmarks have shown that the overhead of the extra CPU is easily offset by the reduction of the amount of data that needs to be copied (and processed) when a thread is created. A little additional memory reduction can be achieved with the L emulation mode: this will prevent the AutoLoader module to be loaded (but have its functionality handled by the "load" pragma). =head1 SOURCE FILTERS If your module wants to use "load" to load subroutines on demand B that module needs a source filter (which is usually activated with a "use" statement), then those modules need to be used when the source of the subroutine is compiled. The class method "register" is intended to be used from such a module, typicallly like this: sub import { my $package = caller(); load->register( $package,__PACKAGE__ ) # register caller's package if defined( $load::VERSION ) # if load.pm loaded and $load::VERSION > 0.11; # and recent enough } The first parameter is the name of the package B which subroutines need extra modules "use"d. The second parameter is the name of the module that needs to be "use"d. =head1 TODO The coordinates of a subroutine in a module (start,number of bytes) are stored in a hash in the load namespace. Ideally, this information should be stored in the stash of the module to which they apply. Then the internals that check for the existence of a subroutine, would see that the subroutine doesn't exist (yet), but that there is an offset and length (and implicitely, a file from %INC) from which the source could be read and evalled. Loading all of the subroutines should maybe be handled inside the Perl parser, having it skip __END__ when the global "now" flag is set. Possibly we should use the handle from a module if there is one, or dup it and use that, rather than opening the file again. Add L emulation mode. =head1 MODULE RATING If you want to find out how this module is appreciated by other people, please check out this module's rating at L (if there are any ratings for this module). If you like this module, or otherwise would like to have your opinion known, you can add your rating of this module at L. =head1 ACKNOWLEDGEMENTS Frank Tolstrup for helping ironing out all of the Windows related issues. =head1 AUTHOR Elizabeth Mattijsen, . Maintained by lnation Please report bugs to . =head1 COPYRIGHT Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2010, 2012 Elizabeth Mattijsen . 2019->2025 LNATION All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L, L. =cut load-0.26/t/PaxHeader/load01.t000644 000765 000024 00000000335 11445614003 016647 xustar00lnationstaff000000 000000 62 LIBARCHIVE.xattr.com.apple.quarantine=MDI4MTs2ODA2MmIxOTs7 53 SCHILY.xattr.com.apple.quarantine=0281;68062b19;; 57 LIBARCHIVE.xattr.com.apple.provenance=AQIAJs5OR7WSpMg 49 SCHILY.xattr.com.apple.provenance=&ÎNGµ’¤È load-0.26/t/load01.t000644 000765 000024 00000026506 11445614003 014706 0ustar00lnationstaff000000 000000 BEGIN { # Magic Perl CORE pragma if ($ENV{PERL_CORE}) { chdir 't' if -d 't'; @INC = '../lib'; } } my @extra; BEGIN { eval { require ifdef }; shift @INC; if ($@) { @extra = (''); } else { $ENV{IFDEF_DIFF} = 0; @extra = ('','-Mifdef=FOO ','-Mifdef=DEBUGGING ' ); } } #BEGIN use Test::More tests => 2 + 2 * ( 3 + (@extra * 2 * ( (5 * (12 + 2 * 6 + 2 * 3)) + (3*3) + (3*3) + (2*3) + (3*3) + (3*3) + (2*3) )) ) + 1; use strict; BEGIN { eval {require warnings} or do {$INC{'warnings.pm'} = ''} } #BEGIN use warnings; use lib 'lib'; BEGIN {use_ok( 'load','ondemand' )} can_ok( 'load',qw( AUTOLOAD import ) ); my $module = "Foo"; my $filepm = "$module.pm"; my $always = "always $load::VERSION"; my $ondemand = "ondemand $load::VERSION"; my $debugging_only = "debugging_only $load::VERSION"; my $ondemand_debugging_only= "ondemand_debugging_only $load::VERSION"; my $bs = ($^O =~ m#MSWin#) ? '' : '\\' ; # Argh, Windows! my $INC = qq{@{[map {"-I$_"} @INC]}}; foreach my $emulation ('','AutoLoader') { my $testmodule = $emulation ? $emulation : 'load'; my $use = ($testmodule eq 'AutoLoader') ? "$testmodule 'AUTOLOAD'" : $testmodule; ok( (open OUT, ">$filepm"), "Create dummy module for testing $testmodule" ); ok( (print OUT <,$always,"Check always with $action" ); ok( (close IN),"Close check always with $action" ); my $do = qq{$^X -I. $INC $extra$action -MFoo -e "${module}::ondemand()" |}; ok( (open( IN,$do )),"Open check ondemand with $action" ); is( scalar ,$ondemand,"Check ondemand with $action") or die $do; ok( (close IN),"Close check ondemand with $action" ); ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "${module}::debugging_only()" 2>stderr |} )), "Open check debugging_only on $action" ); if ($debugging) { is( scalar ,$debugging_only, "Check debugging_only with $_ and $action" ); ok( (close IN), "Close check debugging_only $_ and with $action" ); } else { ok( !defined ,"Check $_ with $action" ); ok( 1 ,"Extra ok for unopened pipe for $_ with $action" ); } ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "${module}::ondemand_debugging_only()" 2>stderr |} )), "Open check ondemand_debugging_only with $action" ); if ($debugging) { is( scalar ,$ondemand_debugging_only, "Check ondemand_debugging_only with $action" ); ok( (close IN), "Close check ondemand_debugging_only with $action" ); } else { ok( !defined ,"Check $_ with $action" ); ok( 1 ,"Extra ok for unopened pipe for $_ with $action" ); } foreach (qw(always ondemand)) { ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "print exists $bs\$Foo::{$_}"|})), "Open check exists $_ with $action" ); is( scalar ,'1',"Check exists $_ with $action" ); ok( (close IN),"Close check exists $_ with $action" ); ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "print Foo->can($_)" |} )), "Open check Foo->can( $_ ) with $action" ); ok( ( =~ m#^CODE#),"Check Foo->can( $_ ) with $action"); ok( (close IN),"Close check Foo->can( $_ ) with $action" ); } foreach ("exists $bs\$Foo::{bar}","Foo->can(bar)") { ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "$_" |} )), "Open check $_ with $action" ); ok( !defined ,"Check $_ with $action" ); ok( (close IN),"Close check $_ bar with $action" ); } } $ENV{'LOAD_NOW'} = 0; $ENV{'LOAD_TRACE'} = 1; foreach ('',qw(ondemand dontscan)) { my $action; if ($_) { $action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_"; } else { $action = $emulation ? "-Mload=$emulation" : ''; } ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "" 2>&1 |} )), "Open trace store $action" ); my $ondemand = $debugging ? <<'EOD' : ''; load: store Foo::ondemand_debugging_only, line \d+ \(offset \d+, \d+ bytes\) EOD like( join( '', ), qr/load: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\) load: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\) $ondemand$/,"Check trace ondemand $action" ); ok( (close IN),"Close trace ondemand $action" ); } foreach ('',qw(ondemand dontscan)) { my $action; if ($_) { $action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_"; } else { $action = $emulation ? "-Mload=$emulation" : ''; } my $ondemand = $debugging ? <<'EOD' : ''; load: store Foo::ondemand_debugging_only, line \d+ \(offset \d+, \d+ bytes\) EOD ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "Foo::empty()" 2>&1|})), "Open trace store load $action" ); like( join( '', ), qr/load: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\) load: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\) ${ondemand}load: ondemand Foo::empty, line \d+ \(offset \d+, \d+ bytes\) $/,"Check trace ondemand $action" ); ok( (close IN),"Close trace ondemand $action: $!" ); } foreach (qw(now env)) { my $action; if ($_ eq 'env') { $ENV{'LOAD_NOW'} = 1; $action = $emulation ? "-Mload=$emulation" : ''; } else { $action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_"; } ok( (open( IN, qq{$^X -I. $INC $extra$action -MFoo -e "Foo::empty()" 2>&1|})), "Open trace store load $action" ); like( join( '', ), qr/load: now Foo, line \d+ \(offset \d+, onwards\) $/,"Check trace now $action" ); ok( (close IN),"Close trace ondemand $action" ); } $ENV{'LOAD_NOW'} = 0; $ENV{'LOAD_TRACE'} = 1; SKIP: { require Config; skip( "No threads support available", (3*3)+(3*3)+(2*3) ) if !$Config::Config{useithreads}; skip( "Cannot check bare AutoLoader yet", (3*3)+(3*3)+(2*3) ) if $emulation; my $ondemand = $debugging ? <<'EOD' : ''; load \[0\]: store Foo::ondemand_debugging_only, line \d+ \(offset \d+, \d+ bytes\) EOD foreach ('',qw(ondemand dontscan)) { my $action; if ($_) { $action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_"; } else { $action = $emulation ? "-Mload=$emulation" : ''; } my $do = qq{$^X -I. $INC $extra$action -Mthreads -MFoo -e "" 2>&1 |}; ok( (open( IN,$do )), "Open trace store $action with threads" ); like( join( '', ), qr/load \[0\]: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\) load \[0\]: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\) $ondemand$/,"Check trace ondemand $action with threads" ) or die $do; ok( (close IN),"Close trace ondemand $action with threads"); } foreach ('',qw(-Mload=ondemand -Mload=dontscan)) { my $action = $_; my $do = qq{$^X -I. $INC $extra$action -Mthreads -MFoo -e "Foo::empty()" 2>&1 |}; ok((open( IN,$do)), "Open trace store load $action with threads" ); like( join( '', ), qr/load \[0\]: store Foo::ondemand, line \d+ \(offset \d+, \d+ bytes\) load \[0\]: store Foo::empty, line \d+ \(offset \d+, \d+ bytes\) ${ondemand}load \[0\]: ondemand Foo::empty, line \d+ \(offset \d+, \d+ bytes\) $/,"Check trace ondemand $action with threads" ) or die $do; ok( (close IN),"Close trace ondemand $action with threads"); } foreach (qw(now env)) { my $action; if ($_ eq 'env') { $ENV{'LOAD_NOW'} = 1; $action = $emulation ? "-Mload=$emulation" : ''; } else { $action = $emulation ? "-Mload=$emulation,$_" : "-Mload=$_"; } ok( (open(IN, qq{$^X -I. $INC $extra$action -Mthreads -MFoo -e "Foo::empty()" 2>&1 |})), "Open trace store load $action with threads" ); like( join( '', ), qr/load \[0\]: now Foo, line \d+ \(offset \d+, onwards\) $/,"Check trace now $action with threads" ); ok( (close IN),"Close trace ondemand $action with threads"); } } } } } #test