Archive-TarGzip
view release on metacpan or search on metacpan
t/Archive/File/Package.pm view on Meta::CPAN
A workaround is hooking in a C<croak> that does not die and collecting
the error messages.
=head1 SUBROUTINES
=head2 eval_str
$error = eval_str( $str );
Runs C<$str> using C<eval>, trapping all the warnings from C<eval> and
returning them as C<$error>.
=head2 is_package_loaded
$package = is_package_loaded($program_module, $package)
The C<is_package_loaded> subroutine determines if the C<$package>
is present and the C<$progarm_module> loaded.
If C<$package> is absent, 0 or '', C<$package> is set to the
C<program_module>.
=head2 load_package
$error = load_package($program_module, @import, [@package_list]);
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' )
( run in 0.982 second using v1.01-cache-2.11-cpan-5a3173703d6 )