Class/Attributes/OOStandard/Decorator.pm

filter: Statementstmt 85.7% 42 / 49 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 86.1% 56 / 65 CC 3 SCAR 4.1
CC
3
Cov
85%
__ANON__
3.0
remove_decoration
1.1
decorate
1.0
CRAP 1.5
« Class/Version.pm ↑ Summary Class/Carp.pm »
1 package Fukurama::Class::Attributes::OOStandard::Decorator;
2 3 ▶use Fukurama::Class::Version(0.02);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Fukurama::Class::Rigid;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Fukurama::Class::HideCaller;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 Fukurama::Class::HideCaller->register_class(__PACKAGE__);
7  
8 =head1 NAME
9  
10 Fukurama::Class::Attributes::OOStandard::Decorator - Helper-class to decorate subroutines
11  
12 =head1 VERSION
13  
14 Version 0.02 (beta)
15  
16 =head1 SYNOPSIS
17  
18 package MyClass;
19 use Fukurama::Class::Attributes::OOStandard::Decorator();
20 my $helper = 'Fukurama::Class::Attributes::OOStandard::DefinitionCheck';
21
22 Fukurama::Class::Attributes::OOStandard::Decorator->decorate('CGI::param', \&CGI::param, $helper);
23  
24 =head1 DESCRIPTION
25  
26 A Helper class for Fukurama::Class::Attributes::OOStandard::DefinitionCheck to decorate subroutines
27 with a subroutine to check parameters and return values and remove the decoration.
28  
29 =head1 EXPORT
30  
31 -
32  
33 =head1 METHODS
34  
35 =over 4
36  
37 =item decorate( method_identifier:STRING, actual_code_reference:\CODE, definition_checker:CLASS) return:VOID
38  
39 Decorates the given method with some parameter and return value checks.
40  
41 =item remove_decoration( method_identifier:STRING, actual_code_reference:\CODE ) return:VOID
42  
43 Remove existing decorations for parameter and return value checks.
44  
45 =back
46  
47 =head1 AUTHOR, BUGS, SUPPORT, ACKNOWLEDGEMENTS, COPYRIGHT & LICENSE
48  
49 see perldoc of L<Fukurama::Class>
50  
51 =cut
52  
53 # STATIC void
54 11 ▶sub decorate {
Subroutine decorate: called CC=1 SCAR=0.0
Pod documented
55 11 my $class = $_[0];
56 11 my $identifier = $_[1];
57 11 my $old = $_[2];
58 11 my $helper = $_[3];
59
60 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
62
63 11 ▶ *{$identifier} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
64 6 $helper->try_check_call($identifier, $_[0]);
65 6 $helper->try_check_access($identifier);
66 5 $helper->try_check_abstract($identifier);
67 5 $helper->try_check_parameter($identifier, [@_[1..$#_]]);
68
69 4 my $context = wantarray();
70 4 ▶ if($context) {
Branch: 2 branches
BranchTrueFalseTotal
if ($context) { } 2 2 4
elsif (defined $context) { } 2 0 2
71 2 my @result = &$old;
72 2 $helper->try_check_result($identifier, \@result, $context);
73 2 return @result;
74 } elsif(defined($context)) {
75 2 my $result = &$old;
76 2 $helper->try_check_result($identifier, [$result], $context);
77 1 return $result;
78 } else {
79 0 goto &$old;
80 }
81 11 };
82 11 return;
83 }
84 # STATIC void
85 0 ▶sub remove_decoration {
Subroutine remove_decoration: not called CC=1 SCAR=1.2
Pod documented
86 0 my $class = $_[0];
87 0 my $identifier = $_[1];
88 0 my $old = $_[2];
89
90 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
91 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
92
93 0 *{$identifier} = $old;
94 0 return;
95 }
96 3 1;
« Class/Version.pm ↑ Summary Class/Carp.pm »