我离开 Perl 世界太久了。我想创建一个子模块并访问它的功能。我基本上只是想念如何连接这些并访问这些方法。
父示例:WWW::Foo
package WWW::Foo
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw( new ) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw( );
our $VERSION = '0.01';
sub new {
my ($package) = @_;
$package::account_name = "Paul";
return bless({}, $package);
}
子示例:WWW::Foo::Bar
package WWW::Foo::Bar
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw( new ) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw( );
our $VERSION = '0.01';
sub print_name {
my ($package) = @_;
# Access parent's package and do basic print.
return;
}
示例脚本
#!/usr/bin/perl -w
use strict;
use WWW::Foo;
use WWW::Foo::Bar;
my $foo = new WWW::Foo();
# Access WWW::Foo::Bar's print_name function