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 ?