Archive-TarGzip
view release on metacpan or search on metacpan
t/Archive/File/Package.pm view on Meta::CPAN
The C<load_package> subroutine attempts to capture any load problems by
loading the package with a "require " under an eval and capturing
all the "warn" and $@ messages.
If the C<$program_module> load is successful,
the checks that the packages in the @package list are present.
If @package list is absent, the C<$program_module> uses
the C<program_module> name as a list of one package.
Although a program module and package have the same name
syntax, they are entirely different.
A program module is a file.
A package is a hash of symbols, a symbol table.
The Perl convention is that the names for each are the same
which enhances the appearance that they are the same
when in fact they are different.
Thus, a program module may have a single package
with a different name or many different packages.
Finally the C<$program_module> subroutine will import the symbols
in the C<@import> list.
If C<@import> is absent C<$program_module> subroutine does not
import any symbols; if C<@import> is '', all symbols are imported.
A C<@import> of 0 usually results in an C<$error>.
The C<$program_module> traps all load errors and all import
C<Carp::Crock> errors and returns them in the C<$error> string.
One very useful application of the C<load_package> subroutine is in test scripts.
If a package does load, it is very helpful that the program does
not die and reports the reason the package did not load.
This information is readily available when loaded at a local site.
However, it the load occurs at a remote site and the load crashes
Perl, the remote tester usually will not have this information
readily available.
Other applications include using backup alternative software
if a package does not load. For example if the package
'Compress::Zlib' did not load, an attempt may be made
to use the gzip system command.
=head1 BUGS
The C<load_package> cannot load program modules whose
name contain the '-' characters.
The 'eval' function used to trap the die errors
believes it means subtraction.
=head1 REQUIREMENTS
Coming.
=head1 DEMONSTRATION
#########
# perl Package.d
###
~~~~~~ Demonstration overview ~~~~~
Perl code begins with the prompt
=>
The selected results from executing the Perl Code
follow on the next lines. For example,
=> 2 + 2
4
~~~~~~ The demonstration follows ~~~~~
=> use File::Package;
=> my $uut = 'File::Package';
=> ##################
=> # Good Load
=> #
=> ###
=> my $error = $uut->load_package( 'File::Basename' )
''
=> $error = $uut->load_package( '_File_::BadLoad' )
'Cannot load _File_::BadLoad
syntax error at E:/User/SoftwareDiamonds/installation/t/File/_File_/BadLoad.pm line 13, near "$FILE "
Global symbol "$FILE" requires explicit package name at E:/User/SoftwareDiamonds/installation/t/File/_File_/BadLoad.pm line 13.
Compilation failed in require at (eval 12) line 1.
Scalar found where operator expected at E:/User/SoftwareDiamonds/installation/t/File/_File_/BadLoad.pm line 13, near "$FILE"
(Missing semicolon on previous line?)
'
=> $uut->load_package( '_File_::BadPackage' )
'# _File_::BadPackage file but package(s) _File_::BadPackage absent.
'
=> $uut->load_package( '_File_::Multi' )
'# _File_::Multi file but package(s) _File_::Multi absent.
'
=> $error = $uut->load_package( '_File_::Hyphen-Test' )
'Cannot load _File_::Hyphen-Test
syntax error at (eval 15) line 1, near "require _File_::Hyphen-"
Warning: Use of "require" without parens is ambiguous at (eval 15) line 1.
'
=> ##################
=> # No &File::Find::find import baseline
=> #
=> ###
=> !defined($main::{'find'})
'1'
=> ##################
=> # Load File::Find, Import &File::Find::find
=> #
=> ###
=> $error = $uut->load_package( 'File::Find', 'find', ['File::Find'] )
''
( run in 1.293 second using v1.01-cache-2.11-cpan-6aa56a78535 )