use strict ; use warnings ;
package ClassTemplate ;
my $VERSION='0.1.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
# -----------------------------------------------------------------------------
# called automatically by perl's garbage collector use to know when
# -----------------------------------------------------------------------------
sub DESTROY {
my $self = shift;
#debug print "the DESTRUCTOR is called \n" ;
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
This class provides handy method for object's handling
=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.0.1 --- ysg --- Initial creation from Template class
=cut
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!