Class/Attributes/OOStandard.pm

filter: Statementstmt 97.1% 67 / 69 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 93.2% 83 / 89 CC 6 SCAR 9.2
CC
6
Cov
92%
Constructor
4.0
Method
3.0
BEGIN
1.0
CRAP 2.5
« Class/Abstract.pm ↑ Summary Class/Version.pm »
1 package Fukurama::Class::Attributes::OOStandard;
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 3 ▶use Fukurama::Class::Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Fukurama::Class::Attributes::OOStandard::DefinitionCheck();
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 3 my $DEF_CHECK = 'Fukurama::Class::Attributes::OOStandard::DefinitionCheck';
8 3 my $SUB_DEF = qr/[a-z \t\n\r]*/;
9 3 my $RETURN_DEF = qr/[a-zA-Z_:, \t\n\r\[\]\(\)]*/;
10 3 my $PARAM_DEF = qr/[a-zA-Z_:, \t\n\r\[\]\(\)]*/;
11
12 3 my $CONSTRUCTOR_DEF_CHECK = qr/^($SUB_DEF\|$PARAM_DEF;?$PARAM_DEF)$/;
13 3 my $METHOD_DEF_CHECK = qr/^($SUB_DEF\|$RETURN_DEF\@?$RETURN_DEF\|$PARAM_DEF;?$PARAM_DEF)$/;
14
15 3 our $LEVEL_CHECK_NONE = 0;
16 3 our $LEVEL_CHECK_SYNTAX = 1;
17 3 our $LEVEL_CHECK_FORCE_INHERITATION = 2;
18 3 our $LEVEL_CHECK_FORCE_ATTRIBUTES = 3;
19
20 3 our $CHECK_LEVEL = $LEVEL_CHECK_FORCE_ATTRIBUTES;
21 3 our $DISABLE_RUNTIME_CHECK;
22
23 =head1 NAME
24
25 Fukurama::Class::Attribute::OOStandard - Plugin for code attributes
26
27 =head1 VERSION
28
29 Version 0.02 (beta)
30
31 =head1 SYNOPSIS
32
33 package MyClass;
34 use Fukurama::Class::Attributes;
35
36 sub my_sub : Method(static|boolean|string,hashref) {
37 my $class = $_[0];
38 my $string = $_[1];
39 my $hashref = $_[2];
40
41 return 1;
42 }
43
44 =head1 DESCRIPTION
45
46 This plugin for Fukurama::Class::Attributes provides code attributes to declare and check
47 method an constructor definitions at compiletime and parameter and return value checks at runtime.
48
49 =head1 CONFIG
50
51 You can define the check-level which describes how the module will check your declarations for methods and constructors.
52 The following levels are allowed:
53
54 =over 4
55
56 =item $Fukurama::Class::Attributes::OOStandard::CHECK_LEVEL = $Fukurama::Class::Attributes::OOStandard::LEVEL_CHECK_NONE
57
58 There is no check. This level is recommended for production.
59
60 =item $Fukurama::Class::Attributes::OOStandard::CHECK_LEVEL = $Fukurama::Class::Attributes::OOStandard::LEVEL_CHECK_SYNTAX
61
62 All registration processes are executed and the definitions of the code attributes would be checked at compiletime.
63 This level is only for the sake of completeness.
64
65 =item $Fukurama::Class::Attributes::OOStandard::CHECK_LEVEL = $Fukurama::Class::Attributes::OOStandard::LEVEL_CHECK_FORCE_INHERITATION
66
67 If you define a code attribute at the parent class, you have to define the same or extended in child class. You can only
68 extend optional parameters and thighten the method access level. All other woud fail at compiletime.
69
70 =item $Fukurama::Class::Attributes::OOStandard::CHECK_LEVEL = $Fukurama::Class::Attributes::OOStandard::LEVEL_CHECK_FORCE_ATTRIBUTES
71
72 The default behavior. You have to define code attributes for all methods in your class, except perl internals.
73
74 =back
75
76 The runtime check for parameter and return values can be disabled by saying:
77
78 $Fukurama::Class::Attributes::OOStandard::DISABLE_RUNTIME_CHECK = 1;
79
80 This is recommended for production.
81
82 =head1 EXPORT
83
84 -
85
86 =head1 METHODS
87
88 =over 4
89
90 =item Constructor( subroutine_data:\HASH ) return:VOID
91
92 Code attribute, which defines a constructor subroutine.
93
94 =item Method( subroutine_data:\HASH ) return:VOID
95
96 Code Attribute, which defines a method.
97
98 =item check_inheritation( method_name:STRING, parent_class:CLASS, child_class:CLASS, inheritation_type:STRING ) return:VOID
99
100 Helper method to compare every method declarations for code attributes in your class whith all in the parent methods.
101
102 =back
103
104 =head1 AUTHOR, BUGS, SUPPORT, ACKNOWLEDGEMENTS, COPYRIGHT & LICENSE
105
106 see perldoc of L<Fukurama::Class>
107
108 =cut
109
110 # STATIC boolean
111 6 ▶sub Constructor {
Subroutine Constructor: called CC=4 SCAR=13.9
Pod documented
112 6 my $class = $_[0];
113 6 my $sub_data = $_[1];
114
115 6 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
116 6 $DEF_CHECK->set_type('constructor');
117 6 ▶ if($sub_data->{'data'} !~ $CONSTRUCTOR_DEF_CHECK) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sub_data->{"data"} =~ /$CONSTRUCTOR_DEF_CHECK/) 0 6 6
118 0 $DEF_CHECK->throw_def_error($sub_data, "constructor syntax is wrong");
119 }
120
121 6 my $def = $DEF_CHECK->resolve_def($sub_data);
122 6 my $sub_def = $def->[0]->[0];
123 6 ▶ if(!grep({$_->{'data'} eq 'static'} @$sub_def)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"data"} eq "static";} @$sub_def) 3 3 6
124 3 push(@$sub_def, {
125 'type' => '',
126 'data' => 'static',
127 });
128 }
129 6 @$sub_def = grep({$_->{'data'} ne ''} @$sub_def);
130 6 my $para_def = $def->[1]->[0];
131 6 my $opt_para_def = $def->[1]->[1];
132 my $result_def = [{
133 'type' => '',
134 6 'data' => $sub_data->{'class'},
135 }];
136 6 my $array_result_def = [];
137
138 6 my $translated_def = $DEF_CHECK->get_translated_def($sub_data, $def, $sub_def, $result_def, $array_result_def, $para_def, $opt_para_def);
139 6 $DEF_CHECK->try_check_translated_def($sub_data, $translated_def, $def);
140 6 ▶ $DEF_CHECK->decorate_sub($translated_def) if(!$DISABLE_RUNTIME_CHECK);
Branch: 1 branch
BranchTrueFalseTotal
unless $Fukurama::Class::Attributes::OOStandard::DISABLE_RUNTIME_CHECK 6 0 6
141 6 return 1;
142 }
143 # STATIC boolean
144 5 ▶sub Method {
Subroutine Method: called CC=3 SCAR=11.1
Pod documented
145 5 my $class = $_[0];
146 5 my $sub_data = $_[1];
147
148 5 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
149 5 $DEF_CHECK->set_type('method');
150 5 ▶ if($sub_data->{'data'} !~ $METHOD_DEF_CHECK) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sub_data->{"data"} =~ /$METHOD_DEF_CHECK/) 0 5 5
151 0 $DEF_CHECK->throw_def_error($sub_data, "method syntax is wrong");
152 }
153
154 5 my $def = $DEF_CHECK->resolve_def($sub_data);
155 5 my $sub_def = $def->[0]->[0];
156 5 my $result_def = $def->[1]->[0];
157 5 my $array_result_def = $def->[1]->[1];
158 5 my $para_def = $def->[2]->[0];
159 5 my $opt_para_def = $def->[2]->[1];
160
161 5 my $translated_def = $DEF_CHECK->get_translated_def($sub_data, $def, $sub_def, $result_def, $array_result_def, $para_def, $opt_para_def);
162 5 $DEF_CHECK->try_check_translated_def($sub_data, $translated_def, $def);
163 5 ▶ $DEF_CHECK->decorate_sub($translated_def) if(!$DISABLE_RUNTIME_CHECK);
Branch: 1 branch
BranchTrueFalseTotal
unless $Fukurama::Class::Attributes::OOStandard::DISABLE_RUNTIME_CHECK 5 0 5
164 5 return 1;
165 }
166 # STATIC void
167 152 ▶sub check_inheritation {
Subroutine check_inheritation: called CC=1 SCAR=0.0
Pod documented
168 152 my $class = $_[0];
169 152 my $method_name = $_[1];
170 152 my $parent_class = $_[2];
171 152 my $child_class = $_[3];
172 152 my $inheritation_type = $_[4];
173
174 152 $DEF_CHECK->check_inheritation($method_name, $parent_class, $child_class, $inheritation_type);
175 152 return;
176 }
177 3 1;
« Class/Abstract.pm ↑ Summary Class/Version.pm »