Package::Anon - Anonymous packages
my $stash = Package::Anon->new; $stash->add_method(bar => sub { 42 }); my $obj = $stash->bless({}); $obj->foo; # 42
my $stash = Package::Anon->new; my $stash = Package::Anon->new('Foo');
Create a new anonymous package. If the optional $name argument is provided, it will be used to set the stash's name. Note that the name is there merely as an aid for debugging - the stash won't be reachable from the global symbol table by the given name.
$name
With no $name given, __ANON__ will be used.
__ANON__
my $instance = $stash->bless({});
Bless a $reference into the anonymous package.
$reference
my $stash = Package::Anon->blessed($obj);
Returns a Package::Anon instance for the package the given $obj is blessed into, or undef if $obj isn't an object.
$obj
$stash->add_method(foo => sub { 42 });
Register a new method in the anonymous package.
my $gv = $stash->create_glob('foo');
Creates a new glob with the name $name, pointing to $stash as its stash.
$stash
The created glob will not be installed into the $stash.
my $gv = $stash->install_glob('foo');
Same as create_glob, but will install the created glob under the given $name within the $stash.
create_glob
add_method is provided as a convenience method to add code symbols to slots in the anonymous stash. Other kinds of symbol table manipulations can be performed as well, but have to be done by hand.
add_method
Currently, Package::Anon instances are blessed stash references, so the following is possible:
Package::Anon
$stash->{$symbol_name} = *$gv;
However, the exact details of how to get a hold of the actual stash reference might change in the future.
Florian Ragwitz <rafl@debian.org>
Ricardo Signes <rjbs@cpan.org>
Jesse Luehrs <doy@tozt.net>
This software is copyright (c) 2012 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Package::Anon, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Package::Anon
CPAN shell
perl -MCPAN -e shell install Package::Anon
For more information on module installation, please visit the detailed CPAN module installation guide.