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 ?


In reply to Re^2: Interfaces by petemar1
in thread Interfaces by haggs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.