POOF

Perl extension that provides stronger typing, encapsulation and inheritance
Download

POOF Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Benny Millares
  • Publisher web site:
  • http://search.cpan.org/~bmillares/

POOF Tags


POOF Description

Perl extension that provides stronger typing, encapsulation and inheritance POOF is a Perl module that attempts to give Perl a more formal OO implementation framework. Providing a distinction between class properties and methods with three levels of access (Public, Protected and Private). It also restricts method overriding in children classes to those properties or methods marked as "Virtual", in which case a child class can override the method but only from its own context. As far as the parent is concern the overridden method or property still behaves in the expected way from its perspective.Take the example above:Any children of MyClass can override the method "OpinionAboutPerl6" as it is marked "Virtual": # in child sub OpinionAboutPerl6 : Method Public { my ($obj) = @_; return "Dude, it's totally tubular!!"; }However if the public method "RealPublicOpinionAboutPerl6" it's called then it would in turn call the "OpinionAboutPerl6" method as it was defined in MyClass, because from the parents perspective the method never changed. I believe this is crucial behavior and it goes along with how the OO principles have been implemented in other popular languages like Java, C# and C++.SYNOPSIS package MyClass; use base qw(POOF); # class properties sub Name : Property Public { { 'type' => 'string', 'default' => '', 'regex' => qr/^.{0,128}$/, } } sub Age : Property Public { { 'type' => 'integer', 'default' => 0, 'min' => 0, 'max' => 120, } } sub marritalStatus : Property Private { { 'type' => 'string', 'default' => 'single', 'regex' => qr/^(?single|married)$/ 'ifilter' => sub { my $val = shift; return lc $val; } } } sub spouse : Property Private { { 'type' => 'string', 'default' => 'single', 'regex' => qr/^.{0,64}$/, 'ifilter' => sub { my $val = shift; return lc $val; } } } sub opinionAboutPerl6 : Property Protected { { 'type' => 'string', 'default' => 'I am so worried, I don't sleep at night.' } } # class methods sub MarritalStatus : Method Public { my ($obj,$requester) = @_; if ($requester eq 'nefarious looking stranger') { return 'non of your business'; } else { return $obj->{'marritalStatus'} } } sub GetMarried : Method Public { my ($obj,$new_spouse) = @_; $obj->{'spouse'} = $new_spouse; if ($obj->pErrors) { my $errors = $obj->pGetErrors; if (exists $errors->{'spouse'}) { die "Problems, the marrige is off!! $errors->{'spouse'} "; return 0; } } else { $obj->{'marritalStatus'} = 'married'; return 1; } } sub OpinionAboutPerl6 : Method Public Virtual { my ($obj) = @_; return "Oh, great, really looking forward to it. It's almost here :)"; } sub RealPublicOpinionAboutPerl6 : Method Public { my ($obj) = @_; return $obj->OpinionAboutPerl6; } Requirements: · Perl


POOF Related Software