Acme-Teddy
view release on metacpan or search on metacpan
lib/Acme/Teddy.pm view on Meta::CPAN
# my $bear = Acme::Teddy->new( {}, @some_data );
#
# Purpose : Dummy constructor
# Parms : $class : Any subclass of this class
# : $self : Any reference
# : @init : All remaining args
# Returns : $self
# Invokes : init()
#
# If invoked with $class only,
# blesses an empty hashref and calls init() with no args.
#
# If invoked with $class and a reference,
# blesses the reference and calls init() with any remaining args.
#
sub new {
my $class = shift;
my $self = shift || {}; # default: hashref
bless ($self => $class);
$self->init(@_);
return $self;
}; ## new
#=========# OBJECT METHOD
#
# $obj->init(@_); # initialize object
#
# Purpose : Discard any extra arguments to new().
lib/Acme/Teddy.pm view on Meta::CPAN
This is a flexible, robust, subclassable object constructor.
my $bear = Acme::Teddy->new();
my $bear = Acme::Teddy->new( [] );
my $bear = Acme::Teddy->new( \&my_sub );
my $bear = Acme::Teddy->new( { -a => 'x' } );
my $bear = Acme::Teddy->new( [ 1, 2, 3, 4 ] );
my $bear = Acme::Teddy->new( {}, @some_data );
It will bless any reference. If invoked with C<$class> only,
blesses an empty hashref and calls L</init()> with no arguments.
If invoked with C<$class> and a reference,
blesses the reference and calls L</init()> with any remaining C<@args>.
=head2 init()
This is a placeholder method. You might want to override it in a subclass.
For common initializations, you can just invoke L</new()> with initial data.
=head1 INTERFACE
{
package Acme::Teddy;
( run in 1.543 second using v1.01-cache-2.11-cpan-de7293f3b23 )