Class::Init - A base constructor class with support for local initialization methods.
package Something::Spiffy; use base Class::Init; sub init { my $self = shift; exists $self->{dsn} || die "parameter 'dsn' missing"; $self->{_dbh} = DBI->connect($self->{dsn}) || die "DBI->connect failed"; } sub users { my $sth = shift->{_dbh}->prepare_cached("SELECT * FROM users"); $sth->execute(@_); return @{ $sth->fetchall_arrayref }; } package main; my $database = Something::Spiffy->new( dsn => '...' ); my @users = $database->users; ...
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.