我已經離開了Perl世界太久了。我想創建一個子模塊並訪問它的功能。我基本上只是錯過了如何連接這些和訪問方法。如何創建子模塊?
家長例如:WWW ::富
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 ::富::酒吧
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
出口'new'是沒有任何意義 – ikegami
正如我說我還沒有在perl的世界很長一段時間,您的評論是關於作爲出口新的一樣有價值。 – paulj