Class::Init - A base constructor class with support for local initialization methods.
package Something::Spiffy; use base qw(Class::Init); sub _init { my $self = shift; exists $self->{dsn} || die "parameter 'dsn' missing"; $self->{_dbh} = DBI->connect($self->{dsn}) || die "DBI->connect failed"; } package main; my $database = Something::Spiffy->new( dsn => '...' ); my @users = $database->{_dbh}->...;
Class::Init provides a constructor, new(), that returns blessed hashrefs by default; that constructor runs all instances of the subroutine _init it finds in the inheritance tree, top-down (EVERY).
new()
_init
EVERY
The goal of this module is to reduce the amount of effort required to construct a simple object class; it helps reduce the amount of code that's duplicated between classes by providing a generic constructor, while allowing individual classes a low-effort way to publish their own changes to the new object.
Richard Soderberg, <perl@crystalflame.net>
Copyright 2004 by Richard Soderberg
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Init, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Init
CPAN shell
perl -MCPAN -e shell install Class::Init
For more information on module installation, please visit the detailed CPAN module installation guide.