Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
go ahead... be a heretic
 
PerlMonks  

Re^2: Interfaces

by petemar1 (Pilgrim)
on Apr 29, 2005 at 20:20 UTC ( [id://452777]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Interfaces
in thread Interfaces

Given...


#!/usr/local/bin/perl -w # Doable.pm # my dbc OOPerl "interface" use strict; use warnings; use FindBin::libs; use Class::Contract; package Doable; { unless( eval { contract { # constant class attr 'NADA'; invar { ${self->NADA} = 0; }; abstract ctor 'new'; abstract dtor; # Control abstract method 'doTheThing'; # Test: DON'T implement doThatThing # and hope an exception is raised. abstract method 'doThatThing'; pre { defined ${Doable::caller} }; }; # end contract sub new; sub DESTROY; sub doTheThing; # sub doThatThing; 1; } # end eval ) { die( "\n\nThere has been a breach of contract.\n\n" ); } # end + unless } 1; # end Doable


#!/usr/local/bin/perl -w # Doer.pm # my OOPerl "implementation" use strict; use warnings; use FindBin::libs; use Class::Contract; use private qw(_semprini); use protected qw(_friendly); use public qw(face); # Should be implementing rather than overloading or overriding use overload "Doable::doTheThing" => "Doer::doTheThing"; use Doable; # I want to IMPLEMENT, # not INHERIT, but anyway... package Doer; @Doer::ISA = qw(Doable); { sub new { my $classname = shift; my $self = bless { }, $classname; $self->{_semprini} = 'naughty'; $self->{face} = 'blank'; return($self); } # end new sub DESTROY { my $self = shift; } # end DESTROY sub doTheThing { print"\nTesting...\n\n"; } # end doTheThing # Don't uncomment unless testing. # sub doThatThing { return(0); } # end doThatThing } 1; # end Doer


#!/usr/local/bin/perl -w # MyApp.pl # my OOPerl "application" use strict; use warnings; use private qw(_MyApp _main _d); use Doer; # I don't want to inherit here, # I just want to "use" and make sub calls package _MyApp; @_MyApp::ISA = qw(Doer); { sub _main; { my $_d = Doer->new; # constructor $_d->doTheThing; # method # print $_d->NADA; # can't see the constant $_d->DESTROY; # destructor print("\nDone! exiting...\n\n"); exit(0); } # end _main } 1; # end _MyApp


...What's a clean way of doing that using Class::Contract ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://452777]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.