use strict ; use warnings ;
package ClassTemplate ;
my $VERSION='0.2.0' ;
use lib '.' ; use Exporter;
my @ISA = qw(AutoLoader Exporter);
my @EXPORT = qw();
BEGIN {
#add the module dir in the INC
$0 =~ m/^(.*)(\\|\/)(.*)\.([a-z]*)/;
push ( @INC , $1) ;
#debug print join ( ' ' , @INC ) ;
} #eof BEGIN
use Logger ;
### START setting package vars
our ( $confHolder , $objLogger , )= () ;
### STOP setting package vars
# ===============================================================
# START OO
# -----------------------------------------------------------------------------
# the constructor
# source:http://www.netalive.org/tinkering/serious-perl/#oop_constructors
# -----------------------------------------------------------------------------
sub new {
my $class = shift ; # Class name is in the first parameter
$confHolder = ${ shift @_ } if ( @_ ) ;
my $self = { }; # Anonymous hash reference holds instance attributes
bless($self, $class); # Say: $self is a $class
$self->Initialize() ;
return $self;
} #eof const
# -----------------------------------------------------------------------------
# perldoc autoloader
# -----------------------------------------------------------------------------
sub AUTOLOAD {
my $self = shift ;
no strict 'refs';
my $name = our $AUTOLOAD;
*$AUTOLOAD = sub {
my $msg = "BOOM! BOOM! BOOM! \n RunTime Error !!!\nUndefined Function $name(@_)\n" ;
print "$self , $msg";
};
goto &$AUTOLOAD; # Restart the new routine.
} #eof sub AUTOLOAD
# -----------------------------------------------------------------------------
# return a field's value
# -----------------------------------------------------------------------------
sub get {
my $self = shift;
my $name = shift;
return $self->{$name};
} #eof sub get
# -----------------------------------------------------------------------------
# set a field's value
# -----------------------------------------------------------------------------
sub set {
my $self = shift;
my $name = shift;
my $value = shift;
$self->{$name}=$value;
} #eof sub set
# -----------------------------------------------------------------------------
# return the fields of this obj instance
# -----------------------------------------------------------------------------
sub dumpFields {
my $self = shift ;
my $strFields = () ;
foreach my $key (keys %$self) {
$strFields .= "$key = $self->{$key}\n";
}
return $strFields ;
} #eof sub dumpFields
# -----------------------------------------------------------------------------
# wrap any logic here on clean up for this class
# -----------------------------------------------------------------------------
sub RunBeforeExit {
print "RunBeforeExit.\n";
}
# -----------------------------------------------------------------------------
# called automatically by perl's garbage collector use to know when
# -----------------------------------------------------------------------------
sub DESTROY {
my $self = shift;
#debug print "the DESTRUCTOR is called \n" ;
$self->RunBeforeExit() ;
return ;
} #eof sub DESTROY
# -----------------------------------------------------------------------------
# Initialize the object with the minimum data it will need to operate
# -----------------------------------------------------------------------------
sub Initialize {
my $self = shift ;
$objLogger = new Logger (\$confHolder) ;
} #eof sub Initialize
# STOP OO
# =============================================================================
1 ;
__END__
=head1 NAME
ClassTemplate
=head1 SYNOPSIS
use ClassTemplate;
=head1 DESCRIPTION
A template like class for starting new classes in the morphus project
=head2 EXPORT
=head1 SEE ALSO
perldoc perlvars
No mailing list for this module
=head1 AUTHOR
yordan.georgiev@gmail.com
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 Yordan Georgiev
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.1 or,
at your option, any later version of Perl 5 you may have available.
VersionHistory:
0.2.0 --- ysg --- Added RunBeforeExit
0.0.1 --- ysg --- Initial creation from Template class
=cut