You're viewing old version number 1. - Current version
Creating Perl Modules and OO Programming
http://www.perlmonks.org/?node_id=586646
Defining classes and inheritance using packages within a single .pl file, without creating modules
http://stackoverflow.com/questions/2621225/how-can-i-call-a-perl-package-i-define-in-the-same-file
http://oreilly.com/catalog/prkunix/excerpt/PWPMch01.html#MARKER-9-23
http://broadcast.oreilly.com/2008/11/beginners-introduction-to-obje.html
http://perldoc.perl.org/perlobj.html
http://www.perl.com/doc/FMTEYEWTK/perltoot.html
http://turtle.ee.ncku.edu.tw/docs/perl/manual/pod/perltoot.html
http://www.perl.com/pub/2002/05/14/mod_perl.html
Excerpts below from an old article, located at:
http://mathforum.org/ken/perl_modules.html
Related:
- http://perldoc.perl.org/perlobj.html
- http://broadcast.oreilly.com/2008/11/beginners-introduction-to-obje.html
Object Oriented Perl syntax
package NewModule;
use strict;
use vars qw($VERSION);
$VERSION = '0.01';
sub new {
my $package = shift;
return bless({}, $package);
}
sub verbose {
my $self = shift;
if (@_) {
$self->{'verbose'} = shift;
}
return $self->{'verbose'};
}
sub hoot {
my $self = shift;
return "Don't pollute!" if $self->{'verbose'};
return;
}
1;
__END__
Test code
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}
use NewModule;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
# Test 2:
my $obj = new NewModule;
$obj->verbose(1);
my $result = $obj->hoot;
print ($result eq "Don't pollute!" ? "ok 2\n" : "not ok 2\n");
# Test 3:
$obj->verbose(0);
my $result = $obj->hoot;
print ($result eq "" ? "ok 3\n" : "not ok 3\n");
Inside-out objects
inside out
[[Perl example of inside-out object]]
[[Perl example of inside-out object number 2]]
http://perltraining.com.au/tips/2006-03-31.html
http://perldoc.perl.org/perlobj.html#Inside-Out-objects
http://perldoc.perl.org/Hash/Util/FieldHash.html
http://search.cpan.org/dist/Object-InsideOut/lib/Object/InsideOut.pod
getters and setters
!!!! http://www.perlmonks.org/?node_id=317885
http://search.cpan.org/~dconway/Class-Std-0.011/lib/Class/Std.pm
From JR's : articles
283 words - 3158 chars
- 1 min read
created on
updated on
- #
source
- versions
Related articles
Creating Perl Modules and OO Programming - Oct 17, 2013
Perl programming tools to test - Nov 14, 2014
Looping through Perl data types - Nov 25, 2013
Perl and OAuth - Dec 03, 2013
Perl Dancer Framework - Dec 19, 2013
more >>