Framework/Base/Object.pm

filter: Statementstmt 63.1% 508 / 804 Branchbran 72.1% 274 / 380 Conditioncond 34.3% 23 / 67 MC/DCmcdc 9.3% 4 / 43 Subroutinesub 64.9% 180 / 277 Podpod 34.6% 87 / 251 totaltotal 59.0% 1076 / 1822 CC 265 SCAR 17.6
CC
265
Cov
64%
___set
72.0
___get
72.0
AUTOLOAD
72.0
CRAP 5.8
« Framework/Feature/Logging.pm ↑ Summary Framework/Base/Object/DumpObj.pm »
1 package App::Framework::Base::Object ;
2  
3 =head1 NAME
4  
5 Object - Basic object
6  
7 =head1 SYNOPSIS
8  
9 use App::Framework::Base::Object ;
10  
11  
12 =head1 DESCRIPTION
13  
14  
15 =head1 DIAGNOSTICS
16  
17 Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages.
18  
19 =head1 AUTHOR
20  
21 Steve Price C<< <sdprice at cpan.org> >>
22  
23 =head1 BUGS
24  
25 None that I know of!
26  
27 =head1 INTERFACE
28  
29 =over 4
30  
31 =cut
32  
33 38 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 35 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 35 ▶use Cwd ;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 35 our $VERSION = "2.002" ;
38 35 our $AUTOLOAD ;
39  
40 #============================================================================================
41 # USES
42 #============================================================================================
43  
44 35 ▶use App::Framework::Base::Object::DumpObj ;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 #============================================================================================
47 # GLOBALS
48 #============================================================================================
49 35 my $global_debug = 0 ;
50 35 my $global_verbose = 0 ;
51 35 my $strict_fields = 0 ;
52  
53 35 my @SPECIAL_FIELDS = qw/
54 global_debug
55 global_verbose
56 strict_fields
57 / ;
58  
59 35 my %COMMON_FIELDS = (
60 'debug' => undef, # pseudo field
61 'verbose' => undef, # pseudo field
62 ) ;
63  
64 # Constant
65 #my @REQ_LIST ;
66 35 my %FIELD_LIST ;
67  
68 my %CLASS_INIT;
69 35 my %CLASS_INSTANCE ;
70  
71 35 my %DEBUG ;
72 35 my %VERBOSE ;
73  
74 #============================================================================================
75 # CONSTRUCTOR
76 #============================================================================================
77  
78 =item B<new([%args])>
79  
80 Create a new object.
81  
82 The %args are specified as they would be in the B<set> method, for example:
83  
84 'mmap_handler' => $mmap_handler
85  
86 Special arguments are:
87  
88 'fields' => Either ARRAY list of valid field names, or HASH of field names with default values
89  
90 Example:
91  
92 new(
93 'fields' => {
94 'cmd' => undef,
95 'status' => 0,
96 'results' => [],
97
98 )
99 )
100  
101 All defined fields have an accessor method created.
102  
103 =cut
104  
105 sub new
106 187 ▶{
Subroutine new: called CC=5 SCAR=16.6
Pod documented
107 187 my ($obj, %args) = @_ ;
108  
109 187 ▶ my $class = ref($obj) || $obj ;
Condition33%1/3
ref $obj || $obj
l!l&&r!l&&!r
01870
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table33%1/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
110 #my $class = $obj->class() ;
111  
112 187 ▶ print "== Object: Creating new $class object ========\n" if $global_debug ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug 1 189 190
113 187 ▶ prt_data("ARGS=", \%args, "\n") if $global_debug>=2 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 2 0 187 187
114  
115 # Initialise class variables
116 187 $class->init_class(%args);
117  
118 # Create object
119 187 my $this = {} ;
120 187 bless ($this, $class) ;
121  
122 # Initialise object
123 187 $this->init(%args) ;
124  
125 # # Check for required settings
126 # foreach (@REQ_LIST)
127 # {
128 # do
129 # {
130 # croak "ERROR: $class : Must specify setting for $_" ;
131 # } unless defined($this->{$_}) ;
132 # }
133  
134 187 ▶ prt_data("== Created object=", $this, "================================================\n") if $global_debug ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug 0 187 187
135
136 187 return($this) ;
137 }
138  
139 #-----------------------------------------------------------------------------
140  
141 =item B<init([%args])>
142  
143 Initialises the newly created object instance.
144  
145  
146 =cut
147  
148 sub init
149 187 ▶{
Subroutine init: called CC=10 SCAR=24.0
Pod documented
150 187 my $this = shift ;
151 187 my (%args) = @_ ;
152  
153 187 ▶ prt_data("init() ARGS=", \%args, "\n") if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 187 187
154  
155 #my $class = $this->class() ;
156 ##my $class = ref($this) || $this ;
157 187 $this = $this->check_instance() ;
158
159 # Defaults
160 ## my %field_list = $this->field_list() ;
161 187 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
18700
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
162 187 my %field_list = ();
163 187 ▶ %field_list = %{ $FIELD_LIST{$class} } if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 187 0 187
164
165  
166 # May have default value for some or all fields
167 187 my %field_copy ;
168 187 foreach my $fld (keys %field_list)
169 {
170 3874 my $val = $field_list{$fld} ;
171
172 # If value is an ARRAY ref or a HASH ref then we want a new copy of this per instance (otherwise
173 # all instances will have a ref to the same HASH/ARRAY and one instance will change all instance's values!)
174 3874 ▶ if (ref($val) eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 1147 2727 3874
elsif (ref $val eq 'HASH') { } 516 2211 2727
175 {
176 1147 $val = [@$val] ;
177 }
178 elsif (ref($val) eq 'HASH')
179 {
180 516 $val = { (%$val) } ;
181 }
182
183 3874 $field_copy{$fld} = $val ;
184 }
185  
186 187 $this->set(%field_copy) ;
187  
188 ## Handle special fields
189 187 foreach my $special (@SPECIAL_FIELDS)
190 {
191 561 ▶ if (exists($args{$special}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{$special}) 0 561 561
192 {
193 # remove from args list
194 0 my $special_val = delete $args{$special} ;
195
196 # call variable handler
197 0 $this->$special($special_val) ;
198 }
199 }
200  
201 ## Set fields from parameters
202 187 $this->set(%args) ;
203  
204 187 ▶ print "init() - done\n" if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 187 187
205  
206 }
207  
208 #-----------------------------------------------------------------------------
209  
210 =item B<init_class([%args])>
211  
212 Initialises the object class variables.
213  
214  
215 =cut
216  
217 sub init_class
218 187 ▶{
Subroutine init_class: called CC=16 SCAR=30.3
Pod documented
219 187 my $this = shift ;
220 187 my (%args) = @_ ;
221  
222 #my $class = $this->class() ;
223 187 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
01870
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
224  
225 187 ▶ prt_data("init_class() ARGS=", \%args, "\n") if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 187 187
226 #prt_data("init_class() ARGS (LIST)=", \@_, "\n") ;
227  
228 187 ▶ if (!$CLASS_INIT{$class})
Branch: 1 branch
BranchTrueFalseTotal
unless ($CLASS_INIT{$class}) 173 14 187
229 {
230 # Field list
231 173 $FIELD_LIST{$class} = {};
232 173 my $fields = delete($args{'fields'}) ;
233  
234 173 ▶ prt_data(" + fields=$fields", $fields, "ARGS=", \%args, "\n") if $global_debug>=4 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 4 0 173 173
235 #prt_data(" init_class($class) FIELDS=", $fields, "\n") ;
236  
237 173 ▶ if ($fields)
Branch: 1 branch
BranchTrueFalseTotal
if ($fields) 173 0 173
238 {
239 173 ▶print " + fields=$fields ref()=", ref($fields), "\n" if $global_debug>=4 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 4 0 173 173
240  
241 173 my $class_fields_href = {} ;
242
243 ## Do the fields
244 173 ▶ if (ref($fields) eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $fields eq 'ARRAY') { } 0 173 173
elsif (ref $fields eq 'HASH') { } 173 0 173
245 {
246 $class_fields_href = {
247 (%COMMON_FIELDS),
248 0 map {$_ => undef} @$fields
249 } ;
250 }
251 elsif (ref($fields) eq 'HASH')
252 {
253 173 $class_fields_href = {
254 (%COMMON_FIELDS),
255 (%$fields)
256 } ;
257 }
258 else
259 {
260 0 $class_fields_href = {
261 (%COMMON_FIELDS),
262 ($fields => undef)
263 } ;
264 }
265
266 173 $FIELD_LIST{$class} = $class_fields_href ;
267 }
268  
269 # create accessors
270 173 my $code = "package $class;\n" ;
271 173 foreach my $field (keys %{$FIELD_LIST{$class}})
272 {
273 3630 ▶ if (!$class->can($field))
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can($field)) 3265 365 3630
274 {
275 3265 $code .= qq{
276 ## get / set
277 sub $field
278 {
279 my \$this = shift ;
280 \@_ ? \$this->{$field} = \$_[0] # set
281 : \$this->{$field}; # get
282 }
283 };
284 }
285
286 3630 ▶ if (!$class->can("undef_$field"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can("undef_$field")) 3284 346 3630
287 {
288 3284 $code .= qq{
289 ## undefine
290 sub undef_$field
291 {
292 my \$this = shift ;
293
294 \$this->{$field} = undef ;
295 }
296 };
297 }
298 }
299
300 173 ▶ print "Created Accessors:\n$code\n" if $global_debug>=4 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 4 0 173 173
301
302 0 ▶ eval $code;
Subroutine array: called CC=2 SCAR=7.3
Subroutine hash: called CC=2 SCAR=7.3
Subroutine notdef: called CC=2 SCAR=7.3
Subroutine string: called CC=2 SCAR=7.3
Subroutine undef_array: not called CC=1 SCAR=0.2
Subroutine undef_hash: not called CC=1 SCAR=0.2
Subroutine undef_notdef: called CC=1 SCAR=0.2
Subroutine undef_string: not called CC=1 SCAR=0.2
Subroutine _arg_list: called CC=2 SCAR=7.3
Subroutine _arg_names_hash: called CC=2 SCAR=7.3
Subroutine _args: called CC=2 SCAR=7.3
Subroutine _data: called CC=2 SCAR=7.3
Subroutine _data_hash: called CC=2 SCAR=7.3
Subroutine _feature_list: called CC=2 SCAR=7.3
Subroutine _feature_methods: called CC=2 SCAR=7.3
Subroutine _fh_list: called CC=2 SCAR=7.3
Subroutine _get_options: called CC=2 SCAR=7.3
Subroutine _logobj: called CC=2 SCAR=7.3
Subroutine _option_fields_hash: called CC=2 SCAR=7.3
Subroutine _options: called CC=2 SCAR=7.3
Subroutine _options_list: called CC=2 SCAR=7.3
Subroutine _required_features: called CC=2 SCAR=7.3
Subroutine _user_options: called CC=2 SCAR=7.3
Subroutine app: called CC=2 SCAR=7.3
Subroutine app: called CC=2 SCAR=7.3
Subroutine app: called CC=2 SCAR=7.3
Subroutine app: called CC=2 SCAR=7.3
Subroutine app: called CC=2 SCAR=7.3
Subroutine app_end_fn: called CC=2 SCAR=7.3
Subroutine app_fn: called CC=2 SCAR=7.3
Subroutine app_start_fn: called CC=2 SCAR=7.3
Subroutine arg_names: called CC=2 SCAR=7.3
Subroutine args: called CC=2 SCAR=7.3
Subroutine argv: called CC=2 SCAR=7.3
Subroutine catch_fn: called CC=2 SCAR=7.3
Subroutine catch_fn: called CC=2 SCAR=7.3
Subroutine catch_fn: called CC=2 SCAR=7.3
Subroutine catch_fn: called CC=2 SCAR=7.3
Subroutine catch_fn: called CC=2 SCAR=7.3
Subroutine catch_fn: called CC=2 SCAR=7.3
Subroutine check_results: called CC=2 SCAR=7.3
Subroutine cmd: called CC=2 SCAR=7.3
Subroutine description: called CC=2 SCAR=7.3
Subroutine dryrun: called CC=2 SCAR=7.3
Subroutine error_str: called CC=2 SCAR=7.3
Subroutine errors: called CC=2 SCAR=7.3
Subroutine errors: called CC=2 SCAR=7.3
Subroutine errors: called CC=2 SCAR=7.3
Subroutine errors: called CC=2 SCAR=7.3
Subroutine errors: called CC=2 SCAR=7.3
Subroutine errors: called CC=2 SCAR=7.3
Subroutine exit_type: called CC=2 SCAR=7.3
Subroutine extension_heap: called CC=2 SCAR=7.3
Subroutine extensions: called CC=2 SCAR=7.3
Subroutine feature_args: called CC=2 SCAR=7.3
Subroutine feature_args: called CC=2 SCAR=7.3
Subroutine feature_args: called CC=2 SCAR=7.3
Subroutine feature_args: called CC=2 SCAR=7.3
Subroutine feature_args: called CC=2 SCAR=7.3
Subroutine feature_config: called CC=2 SCAR=7.3
Subroutine feature_list: called CC=2 SCAR=7.3
Subroutine feature_options: called CC=2 SCAR=7.3
Subroutine feature_options: called CC=2 SCAR=7.3
Subroutine feature_options: called CC=2 SCAR=7.3
Subroutine feature_options: called CC=2 SCAR=7.3
Subroutine feature_options: called CC=2 SCAR=7.3
Subroutine filename: called CC=2 SCAR=7.3
Subroutine history: called CC=2 SCAR=7.3
Subroutine loaded: called CC=2 SCAR=7.3
Subroutine loaded: called CC=2 SCAR=7.3
Subroutine loaded: called CC=2 SCAR=7.3
Subroutine loaded: called CC=2 SCAR=7.3
Subroutine loaded: called CC=2 SCAR=7.3
Subroutine loaded: called CC=2 SCAR=7.3
Subroutine log: called CC=2 SCAR=7.3
Subroutine name: called CC=2 SCAR=7.3
Subroutine name: called CC=2 SCAR=7.3
Subroutine name: called CC=2 SCAR=7.3
Subroutine name: called CC=2 SCAR=7.3
Subroutine name: called CC=2 SCAR=7.3
Subroutine name: called CC=2 SCAR=7.3
Subroutine nice: called CC=2 SCAR=7.3
Subroutine norun: called CC=2 SCAR=7.3
Subroutine on_error: called CC=2 SCAR=7.3
Subroutine option_names: called CC=2 SCAR=7.3
Subroutine package: called CC=2 SCAR=7.3
Subroutine personality: called CC=2 SCAR=7.3
Subroutine priority: called CC=2 SCAR=7.3
Subroutine priority: called CC=2 SCAR=7.3
Subroutine priority: called CC=2 SCAR=7.3
Subroutine priority: called CC=2 SCAR=7.3
Subroutine priority: called CC=2 SCAR=7.3
Subroutine priority: called CC=2 SCAR=7.3
Subroutine progext: called CC=2 SCAR=7.3
Subroutine progname: called CC=2 SCAR=7.3
Subroutine progpath: called CC=2 SCAR=7.3
Subroutine progress: called CC=2 SCAR=7.3
Subroutine registered: called CC=2 SCAR=7.3
Subroutine registered: called CC=2 SCAR=7.3
Subroutine registered: called CC=2 SCAR=7.3
Subroutine registered: called CC=2 SCAR=7.3
Subroutine registered: called CC=2 SCAR=7.3
Subroutine requires: called CC=2 SCAR=7.3
Subroutine requires: called CC=2 SCAR=7.3
Subroutine requires: called CC=2 SCAR=7.3
Subroutine requires: called CC=2 SCAR=7.3
Subroutine requires: called CC=2 SCAR=7.3
Subroutine requires: called CC=2 SCAR=7.3
Subroutine requires_ok: called CC=2 SCAR=7.3
Subroutine requires_ok: called CC=2 SCAR=7.3
Subroutine requires_ok: called CC=2 SCAR=7.3
Subroutine requires_ok: called CC=2 SCAR=7.3
Subroutine requires_ok: called CC=2 SCAR=7.3
Subroutine requires_ok: called CC=2 SCAR=7.3
Subroutine results: called CC=2 SCAR=7.3
Subroutine status: called CC=2 SCAR=7.3
Subroutine summary: called CC=2 SCAR=7.3
Subroutine synopsis: called CC=2 SCAR=7.3
Subroutine timeout: called CC=2 SCAR=7.3
Subroutine undef__arg_list: called CC=1 SCAR=0.2
Subroutine undef__arg_names_hash: not called CC=1 SCAR=0.2
Subroutine undef__args: not called CC=1 SCAR=0.2
Subroutine undef__data: not called CC=1 SCAR=0.2
Subroutine undef__data_hash: not called CC=1 SCAR=0.2
Subroutine undef__feature_list: not called CC=1 SCAR=0.2
Subroutine undef__feature_methods: not called CC=1 SCAR=0.2
Subroutine undef__fh_list: not called CC=1 SCAR=0.2
Subroutine undef__get_options: called CC=1 SCAR=0.2
Subroutine undef__logobj: called CC=1 SCAR=0.2
Subroutine undef__option_fields_hash: not called CC=1 SCAR=0.2
Subroutine undef__options: not called CC=1 SCAR=0.2
Subroutine undef__options_list: not called CC=1 SCAR=0.2
Subroutine undef__required_features: not called CC=1 SCAR=0.2
Subroutine undef__user_options: called CC=1 SCAR=0.2
Subroutine undef_app: called CC=1 SCAR=0.2
Subroutine undef_app: called CC=1 SCAR=0.2
Subroutine undef_app: called CC=1 SCAR=0.2
Subroutine undef_app: called CC=1 SCAR=0.2
Subroutine undef_app: called CC=1 SCAR=0.2
Subroutine undef_app_end_fn: called CC=1 SCAR=0.2
Subroutine undef_app_fn: called CC=1 SCAR=0.2
Subroutine undef_app_start_fn: called CC=1 SCAR=0.2
Subroutine undef_arg_names: not called CC=1 SCAR=0.2
Subroutine undef_args: called CC=1 SCAR=0.2
Subroutine undef_argv: not called CC=1 SCAR=0.2
Subroutine undef_catch_fn: called CC=1 SCAR=0.2
Subroutine undef_catch_fn: called CC=1 SCAR=0.2
Subroutine undef_catch_fn: called CC=1 SCAR=0.2
Subroutine undef_catch_fn: called CC=1 SCAR=0.2
Subroutine undef_catch_fn: called CC=1 SCAR=0.2
Subroutine undef_catch_fn: called CC=1 SCAR=0.2
Subroutine undef_check_results: called CC=1 SCAR=0.2
Subroutine undef_cmd: called CC=1 SCAR=0.2
Subroutine undef_description: not called CC=1 SCAR=0.2
Subroutine undef_dryrun: not called CC=1 SCAR=0.2
Subroutine undef_error_str: not called CC=1 SCAR=0.2
Subroutine undef_errors: not called CC=1 SCAR=0.2
Subroutine undef_errors: not called CC=1 SCAR=0.2
Subroutine undef_errors: not called CC=1 SCAR=0.2
Subroutine undef_errors: not called CC=1 SCAR=0.2
Subroutine undef_errors: not called CC=1 SCAR=0.2
Subroutine undef_errors: not called CC=1 SCAR=0.2
Subroutine undef_exit_type: not called CC=1 SCAR=0.2
Subroutine undef_extension_heap: not called CC=1 SCAR=0.2
Subroutine undef_extensions: not called CC=1 SCAR=0.2
Subroutine undef_feature_args: not called CC=1 SCAR=0.2
Subroutine undef_feature_args: not called CC=1 SCAR=0.2
Subroutine undef_feature_args: not called CC=1 SCAR=0.2
Subroutine undef_feature_args: not called CC=1 SCAR=0.2
Subroutine undef_feature_args: not called CC=1 SCAR=0.2
Subroutine undef_feature_config: not called CC=1 SCAR=0.2
Subroutine undef_feature_list: not called CC=1 SCAR=0.2
Subroutine undef_feature_options: not called CC=1 SCAR=0.2
Subroutine undef_feature_options: not called CC=1 SCAR=0.2
Subroutine undef_feature_options: not called CC=1 SCAR=0.2
Subroutine undef_feature_options: not called CC=1 SCAR=0.2
Subroutine undef_feature_options: not called CC=1 SCAR=0.2
Subroutine undef_filename: called CC=1 SCAR=0.2
Subroutine undef_history: called CC=1 SCAR=0.2
Subroutine undef_loaded: not called CC=1 SCAR=0.2
Subroutine undef_loaded: not called CC=1 SCAR=0.2
Subroutine undef_loaded: not called CC=1 SCAR=0.2
Subroutine undef_loaded: not called CC=1 SCAR=0.2
Subroutine undef_loaded: not called CC=1 SCAR=0.2
Subroutine undef_loaded: not called CC=1 SCAR=0.2
Subroutine undef_log: called CC=1 SCAR=0.2
Subroutine undef_name: not called CC=1 SCAR=0.2
Subroutine undef_name: not called CC=1 SCAR=0.2
Subroutine undef_name: not called CC=1 SCAR=0.2
Subroutine undef_name: not called CC=1 SCAR=0.2
Subroutine undef_name: not called CC=1 SCAR=0.2
Subroutine undef_name: not called CC=1 SCAR=0.2
Subroutine undef_nice: called CC=1 SCAR=0.2
Subroutine undef_norun: not called CC=1 SCAR=0.2
Subroutine undef_on_error: not called CC=1 SCAR=0.2
Subroutine undef_option_names: not called CC=1 SCAR=0.2
Subroutine undef_package: called CC=1 SCAR=0.2
Subroutine undef_personality: called CC=1 SCAR=0.2
Subroutine undef_priority: called CC=1 SCAR=0.2
Subroutine undef_priority: not called CC=1 SCAR=0.2
Subroutine undef_priority: not called CC=1 SCAR=0.2
Subroutine undef_priority: not called CC=1 SCAR=0.2
Subroutine undef_priority: not called CC=1 SCAR=0.2
Subroutine undef_priority: not called CC=1 SCAR=0.2
Subroutine undef_progext: called CC=1 SCAR=0.2
Subroutine undef_progname: called CC=1 SCAR=0.2
Subroutine undef_progpath: called CC=1 SCAR=0.2
Subroutine undef_progress: called CC=1 SCAR=0.2
Subroutine undef_registered: not called CC=1 SCAR=0.2
Subroutine undef_registered: not called CC=1 SCAR=0.2
Subroutine undef_registered: not called CC=1 SCAR=0.2
Subroutine undef_registered: not called CC=1 SCAR=0.2
Subroutine undef_registered: not called CC=1 SCAR=0.2
Subroutine undef_required: not called CC=1 SCAR=0.2
Subroutine undef_requires: not called CC=1 SCAR=0.2
Subroutine undef_requires: not called CC=1 SCAR=0.2
Subroutine undef_requires: not called CC=1 SCAR=0.2
Subroutine undef_requires: not called CC=1 SCAR=0.2
Subroutine undef_requires: not called CC=1 SCAR=0.2
Subroutine undef_requires: not called CC=1 SCAR=0.2
Subroutine undef_requires_ok: not called CC=1 SCAR=0.2
Subroutine undef_requires_ok: not called CC=1 SCAR=0.2
Subroutine undef_requires_ok: not called CC=1 SCAR=0.2
Subroutine undef_requires_ok: not called CC=1 SCAR=0.2
Subroutine undef_requires_ok: not called CC=1 SCAR=0.2
Subroutine undef_requires_ok: not called CC=1 SCAR=0.2
Subroutine undef_results: not called CC=1 SCAR=0.2
Subroutine undef_status: not called CC=1 SCAR=0.2
Subroutine undef_summary: not called CC=1 SCAR=0.2
Subroutine undef_synopsis: not called CC=1 SCAR=0.2
Subroutine undef_timeout: called CC=1 SCAR=0.2
Subroutine undef_usage_fn: called CC=1 SCAR=0.2
Subroutine undef_user_args: not called CC=1 SCAR=0.2
Subroutine undef_user_options: not called CC=1 SCAR=0.2
Subroutine undef_version: called CC=1 SCAR=0.2
Subroutine usage_fn: called CC=2 SCAR=7.3
Subroutine user_args: called CC=2 SCAR=7.3
Subroutine user_options: called CC=2 SCAR=7.3
Subroutine version: called CC=2 SCAR=7.3
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod undocumented
Branch: 119 branches
BranchTrueFalseTotal
@_ ? : 5 4 9
@_ ? : 5 4 9
@_ ? : 2 4 6
@_ ? : 5 4 9
@_ ? : 99 152 251
@_ ? : 58 441 499
@_ ? : 52 367 419
@_ ? : 67 0 67
@_ ? : 67 90 157
@_ ? : 31 1398 1429
@_ ? : 31 1704 1735
@_ ? : 35 72 107
@_ ? : 272 42 314
@_ ? : 15 30 45
@_ ? : 272 385 657
@_ ? : 272 963 1235
@_ ? : 272 0 272
@_ ? : 31 260 291
@_ ? : 33 52 85
@_ ? : 34 266 300
@_ ? : 31 73 104
@_ ? : 35 88 123
@_ ? : 31 377 408
@_ ? : 21 64 85
@_ ? : 12 392 404
@_ ? : 37 299 336
@_ ? : 11 400 411
@_ ? : 52 214 266
@_ ? : 0 15 15
@_ ? : 117 80 197
@_ ? : 37 823 860
@_ ? : 31 0 31
@_ ? : 31 0 31
@_ ? : 35 0 35
@_ ? : 31 0 31
@_ ? : 39 95 134
@_ ? : 2 15 17
@_ ? : 5 44 49
@_ ? : 73 237 310
@_ ? : 23 19 42
@_ ? : 39 24 63
@_ ? : 31 229 260
@_ ? : 31 0 31
@_ ? : 31 0 31
@_ ? : 35 0 35
@_ ? : 31 0 31
@_ ? : 23 18 41
@_ ? : 43 270 313
@_ ? : 31 663 694
@_ ? : 62 229 291
@_ ? : 62 0 62
@_ ? : 62 0 62
@_ ? : 70 74 144
@_ ? : 62 0 62
@_ ? : 43 17 60
@_ ? : 41 379 420
@_ ? : 87 270 357
@_ ? : 62 41 103
@_ ? : 31 41 72
@_ ? : 35 41 76
@_ ? : 62 41 103
@_ ? : 25 38 63
@_ ? : 36 230 266
@_ ? : 37 238 275
@_ ? : 83 837 920
@_ ? : 62 0 62
@_ ? : 62 0 62
@_ ? : 70 0 70
@_ ? : 62 0 62
@_ ? : 44 17 61
@_ ? : 26 47 73
@_ ? : 64 284 348
@_ ? : 62 31 93
@_ ? : 62 0 62
@_ ? : 70 0 70
@_ ? : 62 31 93
@_ ? : 43 21 64
@_ ? : 2 16 18
@_ ? : 17 15 32
@_ ? : 20 35 55
@_ ? : 272 17 289
@_ ? : 42 1115 1157
@_ ? : 31 461 492
@_ ? : 37 332 369
@_ ? : 62 93 155
@_ ? : 62 31 93
@_ ? : 70 35 105
@_ ? : 62 62 124
@_ ? : 44 46 90
@_ ? : 33 231 264
@_ ? : 31 260 291
@_ ? : 31 230 261
@_ ? : 0 15 15
@_ ? : 62 31 93
@_ ? : 31 31 62
@_ ? : 35 35 70
@_ ? : 62 31 93
@_ ? : 27 38 65
@_ ? : 33 261 294
@_ ? : 31 31 62
@_ ? : 31 31 62
@_ ? : 35 35 70
@_ ? : 31 31 62
@_ ? : 24 39 63
@_ ? : 63 261 324
@_ ? : 62 31 93
@_ ? : 62 31 93
@_ ? : 70 35 105
@_ ? : 62 31 93
@_ ? : 61 116 177
@_ ? : 56 30 86
@_ ? : 47 15 62
@_ ? : 56 237 293
@_ ? : 36 237 273
@_ ? : 22 110 132
@_ ? : 79 345 424
@_ ? : 52 34 86
@_ ? : 230 440 670
@_ ? : 26 268 294
303 173 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 173 173
304 0 die "ERROR defining accessors for '$class':"
305 . "\n\t$@\n"
306 . "-----------------------------------------------------\n"
307 . $code;
308 }
309  
310 ## Create private fields
311
312 173 ▶prt_data(" init_class: class=$class FIELD_LIST=", \%FIELD_LIST) if $global_debug>=4 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 4 0 173 173
313  
314 # Finished
315 173 $CLASS_INIT{$class}=1;
316 }
317  
318 187 ▶ print "init_class() - done\n" if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 187 187
319 }
320  
321 #-----------------------------------------------------------------------------
322  
323 =item B<add_fields($fields_href, $args_href)>
324  
325 Adds the contents of the HASH ref $fields_href to the args HASH ref ($args_href) under the key
326 'fields'. Used by derived objects to add their fields to the parent object's fields.
327  
328  
329 =cut
330  
331 sub add_fields
332 555 ▶{
Subroutine add_fields: called CC=2 SCAR=6.9
Pod documented
333 555 my $this = shift ;
334 555 my ($fields_href, $args_href) = @_ ;
335  
336 # Add extra fields
337 555 foreach (keys %$fields_href)
338 {
339 3122 $args_href->{'fields'}{$_} = $fields_href->{$_} ;
340 }
341  
342 }
343  
344 #-----------------------------------------------------------------------------
345  
346 =item B<init_class_instance([%args])>
347  
348 Initialises the object class variables. Creates a class instance so that these
349 methods can also be called via the class (don't need a specific instance)
350  
351 =cut
352  
353 sub init_class_instance
354 0 ▶{
Subroutine init_class_instance: not called CC=1 SCAR=6.9
Pod documented
355 0 my $class = shift ;
356 0 my (%args) = @_ ;
357  
358 0 $class->init_class(%args) ;
359  
360 # Create a class instance object - allows these methods to be called via class
361 0 $class->class_instance(%args) ;
362
363 # Set any global values
364 0 $class->set(%args) ;
365 }
366  
367 #----------------------------------------------------------------------------
368 # Return global fields hash
369 sub _field_list
370 0 ▶{
Subroutine _field_list: not called CC=1 SCAR=6.9
371 0 my $class = shift ;
372  
373 0 return %FIELD_LIST ;
374 }
375  
376 #============================================================================================
377 # CLASS METHODS
378 #============================================================================================
379  
380 #----------------------------------------------------------------------------
381  
382 =item B<global_debug(level)>
383  
384 Set global debug print options to I<level>.
385  
386 0 = No debug
387 1 = standard debug information
388 2 = verbose debug information
389  
390 =cut
391  
392 sub global_debug
393 0 ▶{
Subroutine global_debug: not called CC=2 SCAR=17.9
Pod documented
394 0 my $this = shift ;
395 0 my ($flag) = @_ ;
396  
397 #my $class = $this->class() ;
398 ##my $class = ref($this) || $this ;
399  
400 0 my $old = $global_debug ;
401 0 ▶ $global_debug = $flag if defined($flag) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $flag 0 0 0
402  
403 0 return $old ;
404 }
405  
406  
407 #----------------------------------------------------------------------------
408  
409 =item B<global_verbose(level)>
410  
411 Set global verbose print level to I<level>.
412  
413 0 = None verbose
414 1 = verbose information
415 2 = print commands
416 3 = print command results
417  
418 =cut
419  
420 sub global_verbose
421 0 ▶{
Subroutine global_verbose: not called CC=2 SCAR=17.9
Pod documented
422 0 my $this = shift ;
423 0 my ($flag) = @_ ;
424  
425 #my $class = $this->class() ;
426 ##my $class = ref($this) || $this ;
427  
428 0 my $old = $global_verbose ;
429 0 ▶ $global_verbose = $flag if defined($flag) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $flag 0 0 0
430  
431 0 return $old ;
432 }
433  
434 #----------------------------------------------------------------------------
435  
436 =item B<strict_fields($flag)>
437  
438 Enable/disable strict field checking
439  
440 =cut
441  
442 sub strict_fields
443 0 ▶{
Subroutine strict_fields: not called CC=2 SCAR=17.9
Pod documented
444 0 my $this = shift ;
445 0 my ($flag) = @_ ;
446  
447 #my $class = $this->class() ;
448 ##my $class = ref($this) || $this ;
449  
450 0 my $old = $strict_fields ;
451 0 ▶ $strict_fields = $flag if defined($flag) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $flag 0 0 0
452  
453 0 return $old ;
454 }
455  
456 #----------------------------------------------------------------------------
457  
458 =item B<class_instance([%args])>
459  
460 Returns an object that can be used for class-based calls - object contains
461 all the usual fields
462
463 =cut
464  
465 sub class_instance
466 187 ▶{
Subroutine class_instance: called CC=5 SCAR=16.3
Pod documented
467 187 my $this = shift ;
468 187 my (@args) = @_ ;
469  
470 #my $class = $this->class() ;
471 187 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
01870
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
472  
473 187 ▶ if ($class->allowed_class_instance() && !$class->has_class_instance())
Branch: 1 branch
BranchTrueFalseTotal
if ($class->allowed_class_instance and not $class->has_class_instance) 2 185 187
Condition100%3/3
$class->allowed_class_instance and not $class->has_class_instance
!ll&&!rl&&r
18232
MC/DC100%2/2
$class->allowed_class_instance and not $class->has_class_instance
$class->allowed_class_instance not $class->has_class_instance
Truth table100%3/3
A and not(B)
A= $class->allowed_class_instanceB= not $class->has_class_instance
ABresult
0X0
100
111
474 {
475 2 $CLASS_INSTANCE{$class} = 1 ; # ensure we don't get here again (breaks recursive loop)
476  
477 2 ▶ print "-- Create class instance --\n" if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 2 2
478
479 # Need to create one using the args
480 2 $CLASS_INSTANCE{$class} = $class->new(@args) ;
481 }
482  
483  
484 187 return $CLASS_INSTANCE{$class} ;
485 }
486  
487 #----------------------------------------------------------------------------
488  
489 =item B<has_class_instance()>
490  
491 Returns true if this class has a class instance object
492
493 =cut
494  
495 sub has_class_instance
496 5 ▶{
Subroutine has_class_instance: called CC=2 SCAR=7.6
Pod documented
497 5 my $this = shift ;
498 #my $class = $this->class() ;
499 5 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
500  
501 #prt_data("has_class_instance($class) CLASS_INSTANCE=", \%CLASS_INSTANCE) if $global_debug>=5 ;
502  
503 5 return exists($CLASS_INSTANCE{$class}) ;
504 }
505  
506 #----------------------------------------------------------------------------
507  
508 =item B<allowed_class_instance()>
509  
510 Returns true if this class can have a class instance object
511
512 =cut
513  
514 sub allowed_class_instance
515 5 ▶{
Subroutine allowed_class_instance: called CC=1 SCAR=0.0
Pod documented
516 5 return 1 ;
517 }
518  
519 #----------------------------------------------------------------------------
520  
521 =item B<field_list()>
522  
523 Returns hash of object's field definitions.
524  
525 =cut
526  
527 sub field_list
528 0 ▶{
Subroutine field_list: not called CC=4 SCAR=30.0
Pod documented
529 0 my $this = shift ;
530  
531 #my $class = $this->class() ;
532 0 ▶ my $class = ref($this) || $this ;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
533
534 0 my $href ;
535 0 ▶ $href = $FIELD_LIST{$class} if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 0 0 0
536  
537 0 ▶ return $href ? %$href : () ;
Branch: 1 branch
BranchTrueFalseTotal
$href ? : 0 0 0
538 }
539  
540  
541 #============================================================================================
542 # OBJECT DATA METHODS
543 #============================================================================================
544  
545 #----------------------------------------------------------------------------
546  
547 =item B<debug(level)>
548  
549 Set debug print options to I<level>.
550  
551  
552 =cut
553  
554 sub debug
555 44869 ▶{
Subroutine debug: called CC=4 SCAR=14.0
Pod documented
556 44869 my $this = shift ;
557 44869 my ($level) = @_ ;
558  
559 #my $class = $this->class() ;
560 44869 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
4486900
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
561 #print "In debug() for $class\n" ;
562  
563 44869 ▶ $DEBUG{$class} ||= 0 ;
Condition100%2/2
$DEBUG{$class} ||= 0
l!l
118243687
MC/DC100%1/1
$DEBUG{$class} ||= 0
$DEBUG{$class}
Truth table100%2/2
A
A= $DEBUG{$class}
Aresult
11
00
564 44869 my $old = $DEBUG{$class} ;
565 44869 ▶ $DEBUG{$class} = $level if defined($level) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $level 17 44852 44869
566  
567 44869 return $old ;
568 }
569  
570 #----------------------------------------------------------------------------
571  
572 =item B<undef_debug()>
573  
574 Set debug print options flag to undefined.
575  
576  
577 =cut
578  
579 sub undef_debug
580 187 ▶{
Subroutine undef_debug: called CC=3 SCAR=11.4
Pod documented
581 187 my $this = shift ;
582 187 my ($level) = @_ ;
583  
584 #my $class = $this->class() ;
585 187 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
18700
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
586 #print "In undef_debug() for $class\n" ;
587  
588 187 ▶ $DEBUG{$class} ||= 0 ;
Condition50%1/2
$DEBUG{$class} ||= 0
l!l
0187
MC/DC0%0/1
$DEBUG{$class} ||= 0
$DEBUG{$class}
Truth table50%1/2
A
A= $DEBUG{$class}
Aresult
11
00
589 187 my $old = $DEBUG{$class} ;
590 187 $DEBUG{$class} = undef ;
591  
592 187 return $old ;
593 }
594  
595  
596 #----------------------------------------------------------------------------
597  
598 =item B<verbose(level)>
599  
600 Set verbose print options to I<level>.
601  
602  
603 =cut
604  
605 sub verbose
606 246 ▶{
Subroutine verbose: called CC=4 SCAR=14.8
Pod documented
607 246 my $this = shift ;
608 246 my ($level) = @_ ;
609  
610 #my $class = $this->class() ;
611 246 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
24600
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
612 #print "In verbose() for $class\n" ;
613  
614 246 ▶ $VERBOSE{$class} ||= 0 ;
Condition50%1/2
$VERBOSE{$class} ||= 0
l!l
0246
MC/DC0%0/1
$VERBOSE{$class} ||= 0
$VERBOSE{$class}
Truth table50%1/2
A
A= $VERBOSE{$class}
Aresult
11
00
615 246 my $old = $VERBOSE{$class} ;
616 246 ▶ $VERBOSE{$class} = $level if defined($level) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $level 0 246 246
617  
618 246 return $old ;
619 }
620  
621 #----------------------------------------------------------------------------
622  
623 =item B<undef_verbose()>
624  
625 Set verbose print options flag to undefined.
626  
627  
628 =cut
629  
630 sub undef_verbose
631 187 ▶{
Subroutine undef_verbose: called CC=3 SCAR=11.4
Pod documented
632 187 my $this = shift ;
633 187 my ($level) = @_ ;
634  
635 #my $class = $this->class() ;
636 187 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
18700
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
637 #print "In undef_verbose() for $class\n" ;
638  
639 187 ▶ $DEBUG{$class} ||= 0 ;
Condition50%1/2
$DEBUG{$class} ||= 0
l!l
0187
MC/DC0%0/1
$DEBUG{$class} ||= 0
$DEBUG{$class}
Truth table50%1/2
A
A= $DEBUG{$class}
Aresult
11
00
640 187 my $old = $DEBUG{$class} ;
641 187 $DEBUG{$class} = undef ;
642  
643 187 return $old ;
644 }
645  
646 #----------------------------------------------------------------------------
647  
648 =item B<field_access($field, [$val])>
649  
650 Get/set a field value. Used by derived objects to get/set the underlying object field
651 variable when they have overridden that field's access method.
652  
653 =cut
654  
655 sub field_access
656 34 ▶{
Subroutine field_access: called CC=5 SCAR=16.6
Pod documented
657 34 my $this = shift ;
658 34 my ($field, $value) = @_ ;
659  
660 34 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
3400
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
661 34 my %field_list = ();
662 34 ▶ %field_list = %{ $FIELD_LIST{$class} } if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 34 0 34
663 34 ▶ $this->throw_fatal("Attempting to access an invalid field \"$field\" for this object class \"$class\" ") unless (exists($field_list{$field})) ;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $field_list{$field} 0 34 34
664  
665 34 ▶ $this->{$field} = $value if defined($value) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 19 15 34
666 34 return $this->{$field} ;
667 }
668  
669  
670  
671  
672  
673 #----------------------------------------------------------------------------
674  
675 =item B<set(%args)>
676  
677 Set one or more settable parameter.
678  
679 The %args are specified as a hash, for example
680  
681 set('mmap_handler' => $mmap_handler)
682  
683 Sets field values. Field values are expressed as part of the HASH (i.e. normal
684 field => value pairs).
685  
686 =cut
687  
688 sub set
689 731 ▶{
Subroutine set: called CC=12 SCAR=28.3
Pod documented
690 731 my $this = shift ;
691 731 my (%args) = @_ ;
692  
693 731 ▶ prt_data("set() ARGS=", \%args, "\n") if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 731 731
694  
695 731 $this = $this->check_instance() ;
696
697 # Args
698 ## my %field_list = $this->field_list() ;
699 731 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
73100
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
700 731 my %field_list = ();
701 731 ▶ %field_list = %{ $FIELD_LIST{$class} } if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 731 0 731
702  
703 731 foreach my $field (keys %field_list)
704 {
705 20143 ▶ if (exists($args{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{$field}) 5416 14727 20143
706 {
707 5416 ▶ print " + set $field = $args{$field}\n" if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 5416 5416
708  
709 # Need to call actual method (rather than ___set) so that it can be overridden
710 5416 ▶ if (!defined($args{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{$field}) { } 1263 4153 5416
711 {
712 # Set to undef
713 1263 my $undef_method = "undef_$field" ;
714 1263 $this->$undef_method() ;
715 }
716 else
717 {
718 4153 $this->$field($args{$field}) ;
719 }
720 }
721 }
722  
723 ## See if strict checks are enabled
724 731 ▶ if ($strict_fields)
Branch: 1 branch
BranchTrueFalseTotal
if ($strict_fields) 0 731 731
725 {
726 # Check to ensure that only the valid fields are being set
727 0 foreach my $field (keys %args)
728 {
729 0 ▶ if (!exists($field_list{$field}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $field_list{$field}) 0 0 0
730 {
731 0 print "WARNING::Attempt to set invalid field \"$field\" \n" ;
732 0 $this->dump_callstack() ;
733 }
734 }
735 }
736
737 731 ▶ print "set() - done\n" if $global_debug>=3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 3 0 731 731
738  
739 }
740  
741 #----------------------------------------------------------------------------
742  
743 =item B<vars([@names])>
744  
745 Returns hash of object's fields (i.e. field name => field value pairs).
746  
747 If @names array is specified, then only returns the HASH containing the named fields.
748  
749 =cut
750  
751 sub vars
752 246 ▶{
Subroutine vars: called CC=6 SCAR=18.5
Pod documented
753 246 my $this = shift ;
754 246 my (@names) = @_ ;
755  
756 ## my %field_list = $this->field_list() ;
757 246 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
24600
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
758 246 my %field_list = ();
759 246 ▶ %field_list = %{ $FIELD_LIST{$class} } if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 246 0 246
760  
761 246 my %fields ;
762  
763 #prt_data("vars() names=", \@names) ;
764
765 # If no names specified then get all of them
766 246 ▶ unless (@names)
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 246 0 246
767 {
768 246 @names = keys %field_list ;
769 }
770 246 my %names = map {$_ => 1} @names ;
771 #prt_data(" + names=", \%names) ;
772
773 # Get the value of each field
774 246 foreach my $field (keys %field_list)
775 {
776 # Store field if we've asked for it
777 8635 ▶ $fields{$field} = $this->$field() if exists($names{$field}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $names{$field} 8635 0 8635
778 #print " + + $field : " ;
779 #if (exists($fields{$field}))
780 #{
781 # print "ok ($fields{$field})\n" ;
782 #}
783 #else
784 #{
785 # print "not wanted\n" ;
786 #}
787 }
788
789 246 return %fields ;
790 }
791  
792  
793  
794  
795 #----------------------------------------------------------------------------
796  
797 =item B<DESTROY()>
798  
799 Destroy object
800  
801 =cut
802  
803 sub DESTROY
804 6 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
805 6 my $this = shift ;
806  
807 }
808  
809  
810 #============================================================================================
811 # OBJECT METHODS
812 #============================================================================================
813  
814 #----------------------------------------------------------------------------
815  
816 =item B<check_instance()>
817  
818 If this is not an instance (i.e. a class call), then if there is a class_instance
819 defined use it, otherwise error.
820  
821 =cut
822  
823 sub check_instance
824 940 ▶{
Subroutine check_instance: called CC=4 SCAR=21.7
Pod documented
825 940 my $this = shift ;
826 940 my (%args) = @_ ;
827  
828 #my $class = $this->class() ;
829
830 940 ▶ if (!ref($this))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $this) 0 940 940
831 {
832 0 ▶ my $class = ref($this) || $this ;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
833 0 ▶ if ($class->has_class_instance())
Branch: 1 branch
BranchTrueFalseTotal
if ($class->has_class_instance) { } 0 0 0
834 {
835 0 $this = $class->class_instance() ;
836 }
837 else
838 {
839 0 croak "$this is not a usable object" ;
840 }
841 }
842  
843 940 return $this ;
844 }
845  
846  
847 #----------------------------------------------------------------------------
848  
849 =item B<copy_attributes($target)>
850  
851 Transfers all the supported attributes from $this object to $target object.
852  
853 =cut
854  
855 sub copy_attributes
856 0 ▶{
Subroutine copy_attributes: not called CC=3 SCAR=24.8
Pod documented
857 0 my $this = shift ;
858 0 my ($target) = @_ ;
859  
860 0 $this = $this->check_instance() ;
861 0 $target = $target->check_instance() ;
862
863 # Get list of fields in the target
864 0 my %target_field_list = $target->field_list() ;
865
866 # Copy values from this object
867 0 my %field_list = $this->field_list() ;
868 0 foreach my $field (keys %target_field_list)
869 {
870 # see if can copy
871 0 ▶ if (exists($field_list{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $field_list{$field}) 0 0 0
872 {
873 0 $target->set($field => $this->$field()) ;
874 }
875 }
876
877 }
878  
879 #----------------------------------------------------------------------------
880  
881 =item B<class()>
882  
883 Returns name of object class.
884  
885 =cut
886  
887 sub class
888 86 ▶{
Subroutine class: called CC=2 SCAR=7.6
Pod documented
889 86 my $this = shift ;
890  
891 86 ▶ my $class = ref($this) || $this ;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
8600
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
892
893 86 return $class ;
894 }
895  
896 #----------------------------------------------------------------------------
897  
898 =item B<clone()>
899  
900 Create a copy of this object and return the copy.
901  
902 =cut
903  
904 sub clone
905 0 ▶{
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
906 0 my $this = shift ;
907  
908 0 my $clone ;
909
910 # TODO: WRITE IT!
911
912 0 return $clone ;
913 }
914  
915  
916  
917 # ============================================================================================
918 # UTILITY METHODS
919 # ============================================================================================
920  
921  
922  
923 #----------------------------------------------------------------------------
924  
925 =item B<quote_str($str)>
926  
927 Returns a quoted version of the string.
928
929 =cut
930  
931 sub quote_str
932 0 ▶{
Subroutine quote_str: not called CC=2 SCAR=17.9
Pod documented
933 0 my $this = shift ;
934 0 my ($str) = @_ ;
935
936 ##my $class = $this->class() ;
937  
938 # skip on Windows machines
939 0 ▶ unless ($^O eq 'MSWin32')
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O eq "MSWin32") 0 0 0
940 {
941 # first escape any existing quotes
942 0 $str =~ s%\\'%'%g ;
943 0 $str =~ s%'%'\\''%g ;
944
945 0 $str = "'".$str."'" ;
946 }
947
948
949 0 return $str ;
950 }
951  
952 #----------------------------------------------------------------------------
953  
954 =item B<expand_vars($string, \%vars)>
955  
956 Work through string expanding any variables, replacing them with the value stored in the %vars hash.
957 If variable is not stored in %vars, then that variable is left.
958  
959 Returns expanded string.
960  
961 =cut
962  
963 sub expand_vars
964 0 ▶{
Subroutine expand_vars: not called CC=2 SCAR=13.0
Pod documented
965 0 my $this = shift ;
966 0 my ($string, $vars_href) = @_ ;
967  
968  
969 # Do replacement
970 0 $string =~ s{
971 \$ # find a literal dollar sign
972 \{{0,1} # optional brace
973 (\w+) # find a "word" and store it in $1
974 \}{0,1} # optional brace
975 }{
976 35 ▶ no strict 'refs'; # for $$1 below
Subroutine BEGIN: called CC=1 SCAR=0.0
977 0 ▶ if (defined $vars_href->{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vars_href->{$1}) { } 0 0 0
978 0 $vars_href->{$1}; # expand variable
979 } else {
980 0 "\${$1}"; # leave it
981 }
982 }egx;
983  
984 0 return $string ;
985 }
986  
987  
988  
989 #---------------------------------------------------------------------
990  
991 =item B<prt_data(@args)>
992  
993 Use App::Framework::Base::Object::DumpObj to print out variable information. Automatically enables
994 object print out
995
996 =cut
997  
998 sub prt_data
999 1264 ▶{
Subroutine prt_data: called CC=1 SCAR=0.0
Pod documented
1000 1264 my $this = shift ;
1001 1264 my (@args) = @_ ;
1002
1003 1264 App::Framework::Base::Object::DumpObj::print_objects_flag(1) ;
1004 1264 App::Framework::Base::Object::DumpObj::prt_data(@args) ;
1005 }
1006  
1007 #----------------------------------------------------------------------------
1008 #
1009 #=item B<_dbg_prt($items_aref [, $min_debug])>
1010 #
1011 #Print out the items in the $items_aref ARRAY ref iff the calling object's debug level is >0.
1012 #If $min_debug is specified, will only print out items if the calling object's debug level is >= $min_debug.
1013 #
1014 #=cut
1015 #
1016 sub _dbg_prt
1017 44268 ▶{
Subroutine _dbg_prt: called CC=3 SCAR=11.0
1018 44268 my $obj = shift ;
1019 44268 my ($items_aref, $min_debug) = @_ ;
1020  
1021 44268 ▶ $min_debug ||= 1 ;
Condition100%2/2
$min_debug ||= 1
l!l
344589810
MC/DC100%1/1
$min_debug ||= 1
$min_debug
Truth table100%2/2
A
A= $min_debug
Aresult
11
00
1022
1023 ## check debug level setting
1024 44268 ▶ if ($obj->debug >= $min_debug)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->debug >= $min_debug) 1170 43098 44268
1025 {
1026 1170 my $pkg = ref($obj) ;
1027 1170 $pkg =~ s/App::Framework/ApFw/ ;
1028
1029 1170 my $prefix = App::Framework::Base::Object::DumpObj::prefix("$pkg :: ") ;
1030 1170 $obj->prt_data(@$items_aref) ;
1031 1170 App::Framework::Base::Object::DumpObj::prefix($prefix) ;
1032 }
1033 }
1034  
1035  
1036  
1037 #---------------------------------------------------------------------
1038  
1039 =item B<dump_callstack()>
1040  
1041 Print out the call stack. Useful for debug output at a crash site.
1042 =cut
1043  
1044 sub dump_callstack
1045 12 ▶{
Subroutine dump_callstack: called CC=3 SCAR=11.0
Pod documented
1046 12 my $this = shift ;
1047 12 my ($package, $filename, $line, $subr, $has_args, $wantarray) ;
1048 12 my $i=0 ;
1049 12 print "\n-----------------------------------------\n";
1050 do
1051 12 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
$subr and do { do { () = caller $i++; if ($subr) { print "$filename :: $subr :: $line\n"; } } } 74 12 86
1052 86 ($package, $filename, $line, $subr, $has_args, $wantarray) = caller($i++) ;
1053 86 ▶ if ($subr)
Branch: 1 branch
BranchTrueFalseTotal
if ($subr) 74 12 86
1054 {
1055 74 print "$filename :: $subr :: $line\n" ;
1056 }
1057 }
1058 while($subr) ;
1059 12 print "-----------------------------------------\n\n";
1060 }
1061  
1062  
1063  
1064 # ============================================================================================
1065 # PRIVATE METHODS
1066 # ============================================================================================
1067  
1068 #----------------------------------------------------------------------------
1069 # Set field value
1070 sub ___set
1071 0 ▶{
Subroutine ___set: not called CC=8 SCAR=42.8
1072 0 my $this = shift ;
1073 0 my ($field, $new_value) = @_ ;
1074  
1075 ## NEW
1076 0 ▶if ($global_debug>=10)
Branch: 1 branch
BranchTrueFalseTotal
if ($global_debug >= 10) 0 0 0
1077 {
1078 0 print "Unexpected ___set($field, $new_value)\n" ;
1079 0 $this->dump_callstack() ;
1080 }
1081 ## NEW
1082  
1083  
1084 #my $class = $this->class() ;
1085 0 my $value ;
1086  
1087 # Check that field name is valid
1088 ## my %field_list = $this->field_list() ;
1089 0 ▶ my $class = ref($this) || $this ;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1090 0 my %field_list = ();
1091 0 ▶ %field_list = %{ $FIELD_LIST{$class} } if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 0 0 0
1092  
1093 0 ▶ if (!exists($field_list{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $field_list{$field}) { } 0 0 0
1094 {
1095 ## my $class = ref($this) || $this ;
1096  
1097 0 ▶ prt_data("$class : ___set($field) invalid field. Valid fields=", \%field_list) if $global_debug>=5 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 5 0 0 0
1098 0 ▶ $this->dump_callstack() if $global_debug>=10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 10 0 0 0
1099  
1100 # TODO: Do something more useful!
1101 0 croak "$class: Attempting to write invalid field $field" ;
1102 }
1103 else
1104 {
1105 # get existing value
1106 0 $value = $this->{$field} ;
1107
1108 # write
1109 0 $this->{$field} = $new_value ;
1110 }
1111 0 ▶ print " + ___set($field) <= $new_value (was $value)\n" if $global_debug>=5 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 5 0 0 0
1112  
1113 # Return previous value
1114 0 return $value ;
1115 }
1116  
1117 #----------------------------------------------------------------------------
1118 # get field value
1119 sub ___get
1120 0 ▶{
Subroutine ___get: not called CC=8 SCAR=42.8
1121 0 my $this = shift ;
1122 0 my ($field) = @_ ;
1123  
1124 0 my $value ;
1125
1126 #my $class = $this->class() ;
1127  
1128 ## NEW
1129 0 ▶if ($global_debug>=10)
Branch: 1 branch
BranchTrueFalseTotal
if ($global_debug >= 10) 0 0 0
1130 {
1131 0 print "Unexpected ___get($field)\n" ;
1132 0 $this->dump_callstack() ;
1133 }
1134 ## NEW
1135  
1136  
1137 # Check that field name is valid
1138 ## my %field_list = $this->field_list() ;
1139 0 ▶ my $class = ref($this) || $this ;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1140 0 my %field_list = ();
1141 0 ▶ %field_list = %{ $FIELD_LIST{$class} } if exists($FIELD_LIST{$class}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIELD_LIST{$class} 0 0 0
1142  
1143 0 ▶ if (!exists($field_list{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $field_list{$field}) { } 0 0 0
1144 {
1145 ## my $class = ref($this) || $this ;
1146  
1147 0 ▶ prt_data("$class : ___get($field) invalid field. Valid fields=", \%field_list) if $global_debug>=5 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 5 0 0 0
1148 0 prt_data("$class : ___get($field) invalid field. Valid fields=", \%field_list) ;
1149 0 ▶ $this->dump_callstack() if $global_debug>=10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 10 0 0 0
1150 0 $this->dump_callstack() ;
1151  
1152 # TODO: Do something more useful!
1153 0 croak "$class: Attempting to access invalid method $field (or read using invalid data accessor)" ;
1154 }
1155 else
1156 {
1157 # get existing value
1158 0 $value = $this->{$field} ;
1159 }
1160  
1161 0 ▶ print " + ___get($field) = $value\n" if $global_debug>=5 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 5 0 0 0
1162  
1163 # Return previous value
1164 0 return $value ;
1165 }
1166  
1167  
1168 # ============================================================================================
1169  
1170 # Autoload handle only field value set/undefine
1171 # Set method = <name>
1172 # Undefine method = undef_<name>
1173 #
1174 sub AUTOLOAD
1175 0 ▶{
Subroutine AUTOLOAD: not called CC=8 SCAR=42.8
1176 0 ▶ print "AUTOLOAD ($AUTOLOAD)\n" if $global_debug>=5 ;
Branch: 1 branch
BranchTrueFalseTotal
if $global_debug >= 5 0 0 0
1177  
1178 ## NEW
1179 0 ▶if ($global_debug>=10)
Branch: 1 branch
BranchTrueFalseTotal
if ($global_debug >= 10) 0 0 0
1180 {
1181 0 my $caller = (caller())[0] ;
1182 0 print "Unexpected AUTOLOAD ($AUTOLOAD) from $caller\n" ;
1183 }
1184 ## NEW
1185  
1186 0 my $this = shift;
1187 # prt_data("AUTOLOAD ($AUTOLOAD) this=", $this) if $global_debug>=5 ;
1188  
1189 #print "$this=",ref($this),"\n";
1190 0 ▶ if (!ref($this)||ref($this)eq'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $this or ref $this eq "ARRAY") 0 0 0
Condition0%0/3
not ref $this or ref $this eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $this or ref $this eq "ARRAY"
not ref $this ref $this eq "ARRAY"
Truth table0%0/3
not(A) or B
A= not ref $thisB= ref $this eq "ARRAY"
ABresult
1X1
011
000
1191 {
1192 0 croak "AUTOLOAD ($AUTOLOAD) (@_): $this is not a valid object" ;
1193 }
1194  
1195 0 $this = $this->check_instance() ;
1196 # prt_data(" + this=", $this) if $global_debug>=5 ;
1197  
1198 0 my $name = $AUTOLOAD;
1199 0 $name =~ s/.*://; # strip fully-qualified portion
1200 0 my $class = $AUTOLOAD;
1201 0 $class =~ s/::[^:]+$//; # get class
1202  
1203 0 my $type = ref($this) ;
1204
1205 # if (!$type)
1206 # {
1207 # # see if there is a class instance object defined
1208 # if ($class->has_class_instance())
1209 # {
1210 # $this = $class->class_instance() ;
1211 # $type = ref($this) ;
1212 # }
1213 # else
1214 # {
1215 # croak "$this is not an object";
1216 # }
1217 # }
1218  
1219 # possibly going to set a new value
1220 0 my $set=0;
1221 0 my $new_value = shift;
1222 0 ▶ $set = 1 if defined($new_value) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_value 0 0 0
1223
1224 # 1st see if this is of the form undef_<name>
1225 0 ▶ if ($name =~ m/^undef_(\w+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^undef_(\w+)$/) 0 0 0
1226 {
1227 0 $set = 1 ;
1228 0 $name = $1 ;
1229 0 $new_value = undef ;
1230 }
1231  
1232 0 my $value = $this->___get($name);
1233  
1234 0 ▶ if ($set)
Branch: 1 branch
BranchTrueFalseTotal
if ($set) 0 0 0
1235 {
1236 0 $this->___set($name, $new_value) ;
1237 }
1238  
1239 # Return previous value
1240 0 return $value ;
1241 }
1242  
1243  
1244  
1245 # ============================================================================================
1246 # END OF PACKAGE
1247  
1248 =back
1249  
1250 =cut
1251  
1252 35 1;
1253  
1254 __END__
« Framework/Feature/Logging.pm ↑ Summary Framework/Base/Object/DumpObj.pm »