6. package A b s t r a c t R e n d e r e r ;
sub new { . . . }
sub r e n d e r { die ' I m p l e m e n t me ! ' }
7. package TT ;
use b a s e ' A b s t r a c t R e n d e r e r ' ;
sub r e n d e r {
my $ s e l f = s h i f t ;
my ( $ t e m p l a t e , $ l a y o u t , %v a r s ) = @_;
return $ r e n d e r e d ;
}
package Caml ;
use b a s e ' A b s t r a c t R e n d e r e r ' ;
sub r e n d e r {
my $ s e l f = s h i f t ;
my ( $ t e m p l a t e , %v a r s ) = @_;
return $ r e n d e r e d ;
}
10. Ïðîâåðêà âõîäíûõ è âûõîäíûõ óñëîâèé
Ñëåäîâàíèå ïðèíöèïó ïîäñòàíîâêè Ëèñêîâ (L
â SOLID) ïðè íàñëåäîâàíèè
11. Ïðîâåðêà âõîäíûõ è âûõîäíûõ óñëîâèé
Ñëåäîâàíèå ïðèíöèïó ïîäñòàíîâêè Ëèñêîâ (L
â SOLID) ïðè íàñëåäîâàíèè
Äîêóìåíòèðîâàíèå èíòåðôåéñà
12. package A b s t r a c t R e n d e r e r ;
sub new { . . . }
# R e q u i r e s ( STRING , %HASH_OF_ANY_VALUES)
# E n s u r e s ( STRING )
# Throws ( E x c e p t i o n : : TemplateNotFound )
sub r e n d e r {
my $ s e l f = s h i f t ;
my ( $ t e m p l a t e , %v a r s ) = @_;
...
return $ r e n d e r e d ;
}
13. package TT ;
use b a s e ' A b s t r a c t R e n d e r e r ' ;
sub r e n d e r { . . . }
package Caml ;
use b a s e ' A b s t r a c t R e n d e r e r ' ;
sub r e n d e r { . . . }
23. use C l a s s : : C o n t r a c t ;
contract {
i n h e r i t s ' BaseClass ' ;
c t o r ' new ' ;
method ' methodname ' ;
pre { . . . };
f a i l m s g ' E r r o r message ' ;
post { . . . };
f a i l m s g ' E r r o r message ' ;
impl { . . . };
};
25. use Sub : : C o n t r a c t qw ( c o n t r a c t ) ;
contract ( ' surface ' )
−>i n (& i s _ i n t e g e r , & i s _ i n t e g e r )
−>o u t (& i s _ i n t e g e r )
−>e n a b l e ;
sub s u r f a c e {
# no need to validate arguments anymore !
# just implement the logic :
return $_ [ 0 ] ∗ $_ [ 1 ] ;
}
27. assert
pre => {
' p a r a m e t e r l a r g e r t h a n one ' => '$PARAM [ 0 ] >
},
post => ' $VOID o r $RETURN <= $PARAM [ 0 ] ' ,
sub => ' s q u a r e r o o t ' ,
c o n t e x t => ' n o v o i d ' ,
a c t i o n => ' c a r p ' ;
29. use Carp : : Datum ;
sub r o u t i n e {
DFEATURE my $f_ , " o p t i o n a l message " ;
my ( $a , $b ) = @_;
DREQUIRE $a > $b , " a > b" ;
$a += 1 ; $b += 1 ;
DASSERT $a > $b , " o r d e r i n g a > b p r e s e r v e d " ;
my $ r e s u l t = $b − $a ;
DENSURE $ r e s u l t < 0 ;
return DVAL $ r e s u l t ;
}
31. c o n t r a c t ' add '
=> a c c e p t s [ . . . t y p e . . . ]
=> r e t u r n s v o i d ,
with_context (
p r e => sub {
...
},
p o s t => a s s e r t {
...
}
);
sub add {
my $ s e l f = s h i f t ;
my $ i n c r = s h i f t ;
$ s e l f −>{v a l u e } += $ i n c r ;
return ;
}
33. package A b s t r a c t R e n d e r e r ;
use A t t r i b u t e : : C o n t r a c t ;
sub new { . . . }
sub r e n d e r
: C o n t r a c t R e q u i r e s (VALUE( S t r ) , %ANY)
: C o n t r a c t E n s u r e s (VALUE( S t r ) )
: C o n t r a c t T h r o w s ( E x c e p t i o n : : TemplateNotFound ) {
}