Created
October 31, 2014 23:04
-
-
Save 17e/07879edf40c70d66599d to your computer and use it in GitHub Desktop.
[Moscow.pm] __PACKAGE__ namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use 5.010; | |
package BasePackage; | |
my %STORAGE = (); | |
sub add { | |
my ($class, $key) = @_; | |
say "add $class <- $key"; | |
push @{ $STORAGE{$class} }, $key; | |
} | |
sub list { | |
my $class = shift; | |
print "$class: "; | |
local $, = ','; | |
say @{ $STORAGE{$class} }; | |
} | |
package FirstPackage; | |
our @ISA = ('BasePackage'); | |
__PACKAGE__->add('key0'); | |
__PACKAGE__->add('key1'); | |
package SecondPackage; | |
our @ISA = ('BasePackage'); | |
__PACKAGE__->add('key2'); | |
__PACKAGE__->add('key3'); | |
package main; | |
FirstPackage->list; | |
SecondPackage->list; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
anton@Currant:~$ perl /tmp/example.pl
add FirstPackage <- key0
add FirstPackage <- key1
add SecondPackage <- key2
add SecondPackage <- key3
FirstPackage: key0,key1
SecondPackage: key2,key3