| 1 | package App::Framework::Core ; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | App::Framework::Core - Base application object | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | use App::Framework::Core ; | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | our @ISA = qw(App::Framework::Core) ; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | B<The details of this module are only of interest to personality/extension/feature developers.> | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Base class for applications. Expected to be derived from by an implementable class (like App::Framework::Core::Script). | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 36 | ▶ | use strict ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 35 | ▶ | use Carp ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 34 | our $VERSION = "1.015" ; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #============================================================================================ | ||||||||||||||||||||||||||||
| 30 | # USES | ||||||||||||||||||||||||||||
| 31 | #============================================================================================ | ||||||||||||||||||||||||||||
| 32 | 35 | ▶ | use App::Framework::Base ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 35 | ▶ | use App::Framework::Settings ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 35 | ▶ | use App::Framework::Base::Object::DumpObj ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 35 | ▶ | use File::Basename ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 35 | ▶ | use File::Spec ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 35 | ▶ | use File::Path ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 35 | ▶ | use File::Copy ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 35 | ▶ | use Cwd ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #============================================================================================ | ||||||||||||||||||||||||||||
| 46 | # OBJECT HIERARCHY | ||||||||||||||||||||||||||||
| 47 | #============================================================================================ | ||||||||||||||||||||||||||||
| 48 | 34 | our @ISA = qw(App::Framework::Base) ; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | #============================================================================================ | ||||||||||||||||||||||||||||
| 51 | # GLOBALS | ||||||||||||||||||||||||||||
| 52 | #============================================================================================ | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head2 FIELDS | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | The following fields should be defined either in the call to 'new()' or as part of the application configuration in the __DATA__ section: | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | * name = Program name (default is name of program) | ||||||||||||||||||||||||||||
| 59 | * summary = Program summary text | ||||||||||||||||||||||||||||
| 60 | * synopsis = Synopsis text (default is program name and usage) | ||||||||||||||||||||||||||||
| 61 | * description = Program description text | ||||||||||||||||||||||||||||
| 62 | * history = Release history information | ||||||||||||||||||||||||||||
| 63 | * version = Program version (default is value of 'our $VERSION') | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | * feature_config = HASH ref containing setup information for any installed features. Each feature must have it's own | ||||||||||||||||||||||||||||
| 66 | HASH of values, keyed by the feature name | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | * app_start_fn = Function called before app() function (default is application-defined 'app_start' subroutine if available) | ||||||||||||||||||||||||||||
| 69 | * app_fn = Function called to execute program (default is application-defined 'app' subroutine if available) | ||||||||||||||||||||||||||||
| 70 | * app_end_fn = Function called after app() function (default is application-defined 'app_end' subroutine if available) | ||||||||||||||||||||||||||||
| 71 | * usage_fn = Function called to display usage information (default is application-defined 'usage' subroutine if available) | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | During program execution, the following values can be accessed: | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | * package = Name of the application package (usually main::) | ||||||||||||||||||||||||||||
| 76 | * filename = Full filename path to the application (after following any links) | ||||||||||||||||||||||||||||
| 77 | * progname = Name of the program (without path or extension) | ||||||||||||||||||||||||||||
| 78 | * progpath = Pathname to program | ||||||||||||||||||||||||||||
| 79 | * progext = Extension of program | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =over 4 | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 34 | my %FIELDS = ( | |||||||||||||||||||||||||||
| 87 | ## Object Data | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # User-specified | ||||||||||||||||||||||||||||
| 90 | 'name' => '', | ||||||||||||||||||||||||||||
| 91 | 'summary' => '', | ||||||||||||||||||||||||||||
| 92 | 'synopsis' => '', | ||||||||||||||||||||||||||||
| 93 | 'description' => '', | ||||||||||||||||||||||||||||
| 94 | 'history' => '', | ||||||||||||||||||||||||||||
| 95 | 'version' => undef, | ||||||||||||||||||||||||||||
| 96 | 'feature_config'=> {}, | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 'app_start_fn' => undef, | ||||||||||||||||||||||||||||
| 99 | 'app_fn' => undef, | ||||||||||||||||||||||||||||
| 100 | 'app_end_fn' => undef, | ||||||||||||||||||||||||||||
| 101 | 'usage_fn' => undef, | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 'exit_type' => 'exit', | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Created during init | ||||||||||||||||||||||||||||
| 106 | 'package' => undef, | ||||||||||||||||||||||||||||
| 107 | 'filename' => undef, | ||||||||||||||||||||||||||||
| 108 | 'progname' => undef, | ||||||||||||||||||||||||||||
| 109 | 'progpath' => undef, | ||||||||||||||||||||||||||||
| 110 | 'progext' => undef, | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 'feature_list' => [], # all registered feature names, sorted by priority | ||||||||||||||||||||||||||||
| 113 | '_feature_list' => {}, # all registered features | ||||||||||||||||||||||||||||
| 114 | '_feature_methods' => {}, # HASH or ARRAYs of any methods registered to a feature | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | '_required_features' => [qw/Data Options Args Pod/], | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 'personality' => undef, | ||||||||||||||||||||||||||||
| 119 | 'extensions' => [], | ||||||||||||||||||||||||||||
| 120 | ) ; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # Set of default options | ||||||||||||||||||||||||||||
| 123 | 34 | my @BASE_OPTIONS = ( | |||||||||||||||||||||||||||
| 124 | ['debug=i', 'Set debug level', 'Set the debug level value', ], | ||||||||||||||||||||||||||||
| 125 | ) ; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 34 | our %LOADED_MODULES ; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 34 | our $class_debug = 0 ; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | #============================================================================================ | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =back | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head2 CONSTRUCTOR METHODS | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =over 4 | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | #============================================================================================ | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =item B<new([%args])> | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Create a new App::Framework::Core. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | The %args are specified as they would be in the B<set> method, for example: | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 'mmap_handler' => $mmap_handler | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | The full list of possible arguments are : | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 'fields' => Either ARRAY list of valid field names, or HASH of field names with default values | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub new | ||||||||||||||||||||||||||||
| 159 | 31 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 31 | my ($obj, %args) = @_ ; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 31 | ▶ | my $class = ref($obj) || $obj ; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $obj || $obj
MC/DC0%0/2
ref $obj || $obj
ref $obj
$obj
Truth table33%1/3
A || B
A= ref $objB= $obj
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | ## stop 'app' entry from being displayed in Features | ||||||||||||||||||||||||||||
| 165 | 31 | App::Framework::Base::Object::DumpObj::exclude('app') ; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 31 | ▶ | print "App::Framework::Core->new() class=$class\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 31 | ▶ | my $caller_info_aref = delete $args{'_caller_info'} || croak "$class must be called via App::Framework" ; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'_caller_info'} || croak("$class must be called via App::Framework")
MC/DC0%0/1
delete $args{'_caller_info'} || croak("$class must be called via App::Framework")
delete $args{'_caller_info'}
Truth table50%1/2
A
A= delete $args{'_caller_info'}
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Create object | ||||||||||||||||||||||||||||
| 172 | 31 | my $this = $class->SUPER::new(%args) ; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # Set up error handler | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | $this->set('catch_fn' => sub {$this->catch_error(@_);} ) ; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | ## Get caller information | ||||||||||||||||||||||||||||
| 178 | 31 | my ($package, $filename, $line, $subr, $has_args, $wantarray) = @$caller_info_aref ; | |||||||||||||||||||||||||||
| 179 | 31 | $this->set( | |||||||||||||||||||||||||||
| 180 | 'package' => $package, | ||||||||||||||||||||||||||||
| 181 | 'filename' => $filename, | ||||||||||||||||||||||||||||
| 182 | ) ; | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | ## now import packages into the caller's namespace | ||||||||||||||||||||||||||||
| 185 | 31 | $this->_import() ; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | ## Set program info | ||||||||||||||||||||||||||||
| 189 | 31 | $this->set_paths($filename) ; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | ## set up functions | ||||||||||||||||||||||||||||
| 192 | # foreach my $fn (qw/app_start app app_end usage/) | ||||||||||||||||||||||||||||
| 193 | 31 | foreach my $fn_aref ( | |||||||||||||||||||||||||||
| 194 | # prefered | ||||||||||||||||||||||||||||
| 195 | ['app_start', 'app_start'], | ||||||||||||||||||||||||||||
| 196 | ['app', 'app'], | ||||||||||||||||||||||||||||
| 197 | ['app_end', 'app_end'], | ||||||||||||||||||||||||||||
| 198 | ['usage', 'usage'], | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # alternates | ||||||||||||||||||||||||||||
| 201 | ['app_begin', 'app_start'], | ||||||||||||||||||||||||||||
| 202 | ['app_enter', 'app_start'], | ||||||||||||||||||||||||||||
| 203 | ['app_init', 'app_start'], | ||||||||||||||||||||||||||||
| 204 | ['app_finish', 'app_end'], | ||||||||||||||||||||||||||||
| 205 | ['app_exit', 'app_end'], | ||||||||||||||||||||||||||||
| 206 | ['app_term', 'app_end'], | ||||||||||||||||||||||||||||
| 207 | ) | ||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||
| 209 | 310 | my ($fn, $alias) = @$fn_aref ; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # Only add function if it's not already been specified | ||||||||||||||||||||||||||||
| 212 | 310 | $this->_register_fn($fn, $alias) ; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | ## Get version | ||||||||||||||||||||||||||||
| 216 | 31 | $this->_register_scalar('VERSION', 'version') ; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | ## Ensure name set | ||||||||||||||||||||||||||||
| 219 | 31 | ▶ | if (!$this->name()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||
| 221 | 31 | $this->name($this->progname() ) ; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | ## Set up default timezone | ||||||||||||||||||||||||||||
| 226 | 31 | ▶ | if (exists($LOADED_MODULES{'Date::Manip'})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||
| 228 | 31 | ▶ | my $tz = $App::Frameowrk::Settings::DATE_TZ || 'GMT' ; | ||||||||||||||||||||||||||
|
Condition50%1/2
$App::Frameowrk::Settings::DATE_TZ || 'GMT'
MC/DC0%0/1
$App::Frameowrk::Settings::DATE_TZ || 'GMT'
$App::Frameowrk::Settings::DATE_TZ
Truth table50%1/2
A
A= $App::Frameowrk::Settings::DATE_TZ
| |||||||||||||||||||||||||||||
| 229 | 31 | ▶ | my $fmt = $App::Frameowrk::Settings::DATE_FORMAT || 'non-US' ; | ||||||||||||||||||||||||||
|
Condition50%1/2
$App::Frameowrk::Settings::DATE_FORMAT || 'non-US'
MC/DC0%0/1
$App::Frameowrk::Settings::DATE_FORMAT || 'non-US'
$App::Frameowrk::Settings::DATE_FORMAT
Truth table50%1/2
A
A= $App::Frameowrk::Settings::DATE_FORMAT
| |||||||||||||||||||||||||||||
| 230 | 31 | eval { | |||||||||||||||||||||||||||
| 231 | 31 | my $date = new Date::Manip::Date; | |||||||||||||||||||||||||||
| 232 | 31 | $date->config("setdate", "zone,$tz") ; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | #&Date_Init("TZ=$tz", "DateFormat=$fmt") ; | ||||||||||||||||||||||||||||
| 235 | } ; | ||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | ## Install required features | ||||||||||||||||||||||||||||
| 239 | 31 | $this->install_features($this->_required_features) ; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | ## Need to do some init of required features | ||||||||||||||||||||||||||||
| 242 | 31 | $this->feature('Options')->append_options(\@BASE_OPTIONS) ; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 31 | ▶ | print "App::Framework::Core->new() - END\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 31 | return($this) ; | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | #============================================================================================ | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =back | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =head2 CLASS METHODS | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =over 4 | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | #============================================================================================ | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =item B<init_class([%args])> | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | Initialises the App::Framework::Core object class variables. | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub init_class | ||||||||||||||||||||||||||||
| 272 | 31 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 273 | 31 | my $class = shift ; | |||||||||||||||||||||||||||
| 274 | 31 | my (%args) = @_ ; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | # Add extra fields | ||||||||||||||||||||||||||||
| 277 | 31 | $class->add_fields(\%FIELDS, \%args) ; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | # init class | ||||||||||||||||||||||||||||
| 280 | 31 | $class->SUPER::init_class(%args) ; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | =item B<allowed_class_instance()> | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | Class instance object is not allowed | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | sub allowed_class_instance | ||||||||||||||||||||||||||||
| 293 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
allowed_class_instance: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 294 | 0 | return 0 ; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | =item B<dynamic_load($module [, $pkg])> | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | Attempt to load the module into the specified package I<$pkg> (or load it into a temporary space). | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | Then checks that the load was ok by checking the module's version number. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Returns 1 on success; 0 on failure. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | sub dynamic_load | ||||||||||||||||||||||||||||
| 310 | 545 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dynamic_load: called CC=9 SCAR=23.9
Pod
documented
| |||||||||||||||||||||||||||||
| 311 | 545 | my $class = shift ; | |||||||||||||||||||||||||||
| 312 | 545 | my ($module, $pkg) = @_ ; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 545 | my $loaded = 0 ; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | # for windoze.... | ||||||||||||||||||||||||||||
| 317 | 545 | ▶ | if ($^O =~ /MSWin32/i) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||
| 319 | 0 | ▶ | return 0 unless $class->find_lib($module) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 545 | ▶ | $pkg ||= 'temp_app_pkg' ; | ||||||||||||||||||||||||||
|
Condition100%2/2
$pkg ||= "temp_app_pkg"
MC/DC100%1/1
$pkg ||= "temp_app_pkg"
$pkg
Truth table100%2/2
A
A= $pkg
| |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 545 | ▶ | print "dynamic_load($module) into $pkg\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 545 | my $version ; | |||||||||||||||||||||||||||
| 327 | 0 | ▶ | eval " | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 328 | package $pkg; | ||||||||||||||||||||||||||||
| 329 | use $module; | ||||||||||||||||||||||||||||
| 330 | \$version = \$${module}::VERSION ; | ||||||||||||||||||||||||||||
| 331 | " ; | ||||||||||||||||||||||||||||
| 332 | #print "Version = $version\n" ; | ||||||||||||||||||||||||||||
| 333 | 545 | ▶ | if ($@) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | 315 | ▶ | print "dynamic_load($module, $pkg) : error : $@\nAborting dynamic_load.\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | elsif (defined($version)) | ||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||
| 339 | 230 | $loaded = 1 ; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 545 | ▶ | print "dynamic_load($module, $pkg) : loaded = $loaded.\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 545 | return $loaded ; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | =item B<dynamic_isa($module)> | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | Load the module into the caller's namespace then set it's @ISA ready for that | ||||||||||||||||||||||||||||
| 351 | module to call it's parent's new() method | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =cut | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | sub dynamic_isa | ||||||||||||||||||||||||||||
| 356 | 74 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dynamic_isa: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||
| 357 | 74 | my $class = shift ; | |||||||||||||||||||||||||||
| 358 | 74 | my ($module, $pkg) = @_ ; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 74 | ▶ | unless ($pkg) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||
| 362 | 0 | my @callinfo = caller(0); | |||||||||||||||||||||||||||
| 363 | 0 | $pkg = $callinfo[0] ; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | 74 | my $loaded = $class->dynamic_load($module, $pkg) ; | |||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 74 | ▶ | if ($loaded) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | { | ||||||||||||||||||||||||||||
| 369 | 35 | ▶ | no strict 'refs' ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | ## Create ourself as if we're an object of the required type (but only if ISA is not already set) | ||||||||||||||||||||||||||||
| 372 | 74 | ▶ | if (!scalar(@{"${pkg}::ISA"})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | { | ||||||||||||||||||||||||||||
| 374 | 66 | ▶ | print "dynamic_isa() $pkg set ISA=$module\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 66 | @{"${pkg}::ISA"} = ( $module ) ; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | else | ||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||
| 379 | 0 | ▶ | print "dynamic_isa() - $pkg already got ISA=",@{"${pkg}::ISA"}," (wanted to set $module)\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 74 | return $loaded ; | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =item B< inherit($caller_class, [%args]) > | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | Initialises the object class variables. | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | =cut | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | sub inherit | ||||||||||||||||||||||||||||
| 397 | 37 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
inherit: called CC=19 SCAR=31.9
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | 37 | my $class = shift ; | |||||||||||||||||||||||||||
| 399 | 37 | my ($caller_class, %args) = @_ ; | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | ## get calling package | ||||||||||||||||||||||||||||
| 402 | 37 | my $caller_pkg = (caller(0))[0] ; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 37 | ▶ | print "\n\n----------------------------------------\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | 37 | ▶ | print "Core:inherit() caller=$caller_pkg\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | ## get inheritence stack, grab this object's class, restore list | ||||||||||||||||||||||||||||
| 408 | 37 | ▶ | my $inheritence = delete $args{'_inheritence'} || [] ; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'_inheritence'} || []
MC/DC0%0/1
delete $args{'_inheritence'} || []
delete $args{'_inheritence'}
Truth table50%1/2
A
A= delete $args{'_inheritence'}
| |||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 37 | ▶ | print " + inherit=\n\t".join("\n\t", @$inheritence)."\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | ## Get parent and restore new list | ||||||||||||||||||||||||||||
| 413 | 37 | my $parent = shift @$inheritence ; | |||||||||||||||||||||||||||
| 414 | 37 | $args{'_inheritence'} = $inheritence ; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 37 | ▶ | print "Core: $caller_class parent=$parent inherit=@$inheritence\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | ## load in base objects | ||||||||||||||||||||||||||||
| 419 | 37 | my $_caller = $parent ; | |||||||||||||||||||||||||||
| 420 | 37 | foreach my $_parent (@$inheritence) | |||||||||||||||||||||||||||
| 421 | { | ||||||||||||||||||||||||||||
| 422 | 6 | ▶ | print " + Preloading: load $_parent into $_caller\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | ## Dynamic load this parent into this caller | ||||||||||||||||||||||||||||
| 425 | 6 | my $loaded = App::Framework::Core->dynamic_isa($_parent, $_caller) ; | |||||||||||||||||||||||||||
| 426 | 6 | ▶ | croak "Sorry, failed to load \"$_parent\"" unless $loaded ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 6 | ▶ | App::Framework::Core::_dumpvar($_caller) if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 6 | ▶ | App::Framework::Core::_dumpvar($_parent) if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | # update caller for next time round | ||||||||||||||||||||||||||||
| 432 | 6 | $_caller = $_parent ; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 37 | ▶ | print " + Loading: load $parent into $caller_pkg\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | ## Dynamic load this object | ||||||||||||||||||||||||||||
| 438 | 37 | my $loaded = App::Framework::Core->dynamic_isa($parent, $caller_pkg) ; | |||||||||||||||||||||||||||
| 439 | 37 | ▶ | croak "Sorry, failed to load \"$parent\"" unless $loaded ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 37 | ▶ | App::Framework::Core::_dumpvar($caller_pkg) if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 37 | ▶ | App::Framework::Core::_dumpvar($parent) if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 37 | ▶ | print "Core: calling $caller_pkg -> $parent ::new()\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 37 | ▶ | App::Framework::Core::_dumpisa($caller_pkg) if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | ## Create object | ||||||||||||||||||||||||||||
| 448 | 37 | my $this ; | |||||||||||||||||||||||||||
| 449 | { | ||||||||||||||||||||||||||||
| 450 | 35 | ▶ | no strict 'refs' ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 37 | $this = &{"${parent}::new"}( | |||||||||||||||||||||||||||
| 453 | $caller_class, | ||||||||||||||||||||||||||||
| 454 | %args, | ||||||||||||||||||||||||||||
| 455 | ) ; | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 37 | ▶ | print "Core:inherit() - END\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | 37 | ▶ | print "----------------------------------------\n\n" if $class_debug ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 37 | return $this ; | |||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | =item B< find_lib($module) > | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | Looks for the named module in the @INC path. If found, checks the package name inside the file | ||||||||||||||||||||||||||||
| 471 | to ensure that it really matches the capitalisation. | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | (Mainly for Microsoft Windows use!) | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | =cut | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | sub find_lib | ||||||||||||||||||||||||||||
| 478 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
find_lib: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 479 | 0 | my $class = shift ; | |||||||||||||||||||||||||||
| 480 | 0 | my ($module) = @_ ; | |||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 0 | my @module_dirs = split /::/, $module ; | |||||||||||||||||||||||||||
| 483 | 0 | my $pm = pop @module_dirs ; | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | #print "find_lib($module)\n" ; | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 0 | my $found ; | |||||||||||||||||||||||||||
| 488 | 0 | foreach my $dir (@INC) | |||||||||||||||||||||||||||
| 489 | { | ||||||||||||||||||||||||||||
| 490 | 0 | my $file = File::Spec->catfile($dir, @module_dirs, "$pm.pm") ; | |||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | #print " + checking $file\n" ; | ||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if (-f $file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if (open my $fh, "<$file") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||
| 497 | 0 | my $line ; | |||||||||||||||||||||||||||
| 498 | 0 | ▶ | while (defined($line = <$fh>)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||||
| 500 | 0 | chomp $line ; | |||||||||||||||||||||||||||
| 501 | 0 | ▶ | if ($line =~ m/^\s*package\s+$module\s*;/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||
| 503 | 0 | $found = $module ; | |||||||||||||||||||||||||||
| 504 | 0 | last ; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | 0 | close $fh ; | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | 0 | ▶ | last if $found ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | #print "find_lib() = $found\n" ; | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 0 | return $found ; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | =item B< lib_glob($module_path) > | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | Looks for any perl modules contained under the module path. Looks at all possible locations | ||||||||||||||||||||||||||||
| 523 | in the @INC path, returning the first found. | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | Returns a HASH contains the module name as key and the full filename path as the value. | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | =cut | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | sub lib_glob | ||||||||||||||||||||||||||||
| 530 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
lib_glob: not called CC=4 SCAR=25.3
Pod
documented
| |||||||||||||||||||||||||||||
| 531 | 0 | my $class = shift ; | |||||||||||||||||||||||||||
| 532 | 0 | my ($module_path) = @_ ; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 0 | my %libs ; | |||||||||||||||||||||||||||
| 535 | 0 | foreach my $dir (@INC) | |||||||||||||||||||||||||||
| 536 | { | ||||||||||||||||||||||||||||
| 537 | 0 | my $module_path = File::Spec->catfile($dir, $module_path, "*.pm") ; | |||||||||||||||||||||||||||
| 538 | 0 | ▶ | my @files = glob($module_path) ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 539 | 0 | foreach my $file (@files) | |||||||||||||||||||||||||||
| 540 | { | ||||||||||||||||||||||||||||
| 541 | 0 | my ($base, $path, $ext) = fileparse($file, '\..*') ; | |||||||||||||||||||||||||||
| 542 | 0 | ▶ | if (!exists($libs{$base})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 543 | { | ||||||||||||||||||||||||||||
| 544 | 0 | $libs{$base} = $file ; | |||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 0 | return %libs ; | |||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | =item B<isa_tree(package)> | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | Starting at I<package>, return a HASH ref in the form of a tree of it's parents. They keys are the parent module | ||||||||||||||||||||||||||||
| 557 | names, and the values are HASH refs of their parents and so on. Value is undef when last parent | ||||||||||||||||||||||||||||
| 558 | is reached. | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =cut | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | sub isa_tree | ||||||||||||||||||||||||||||
| 563 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isa_tree: not called CC=2 SCAR=9.6
Pod
documented
| |||||||||||||||||||||||||||||
| 564 | 35 | ▶ | no strict "vars" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 565 | 35 | ▶ | no strict "refs" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | 0 | my $class = shift ; | |||||||||||||||||||||||||||
| 568 | 0 | my ($packageName) = @_; | |||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 0 | my $tree_href = {} ; | |||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 0 | foreach my $isa (@{"${packageName}::ISA"}) | |||||||||||||||||||||||||||
| 574 | { | ||||||||||||||||||||||||||||
| 575 | 0 | $tree_href->{$isa} = $class->isa_tree($isa) ; | |||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 0 | return $tree_href ; | |||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | #============================================================================================ | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | =back | ||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | =head2 OBJECT METHODS | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | =over 4 | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | =cut | ||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | #============================================================================================ | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | =item B<set_paths($filename)> | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | Get the full path to this application (follows links where required) | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | =cut | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | sub set_paths | ||||||||||||||||||||||||||||
| 602 | 64 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_paths: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||
| 603 | 64 | my $this = shift ; | |||||||||||||||||||||||||||
| 604 | 64 | my ($filename) = @_ ; | |||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | # Follow links | ||||||||||||||||||||||||||||
| 607 | 64 | $filename = File::Spec->rel2abs($filename) ; | |||||||||||||||||||||||||||
| 608 | 64 | ▶ | while ( -l $filename) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | { | ||||||||||||||||||||||||||||
| 610 | 0 | $filename = readlink $filename ; | |||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | # Get info | ||||||||||||||||||||||||||||
| 614 | 64 | my ($progname, $progpath, $progext) = fileparse($filename, '\.[^\.]+') ; | |||||||||||||||||||||||||||
| 615 | 64 | ▶ | if (ref($this)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 616 | { | ||||||||||||||||||||||||||||
| 617 | # set if not class call | ||||||||||||||||||||||||||||
| 618 | 31 | $this->set( | |||||||||||||||||||||||||||
| 619 | 'progname' => $progname, | ||||||||||||||||||||||||||||
| 620 | 'progpath' => $progpath, | ||||||||||||||||||||||||||||
| 621 | 'progext' => $progext, | ||||||||||||||||||||||||||||
| 622 | ) ; | ||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | # Set up include path to add script home + script home /lib subdir | ||||||||||||||||||||||||||||
| 626 | 64 | my %inc = map {$_=>1} @INC ; | |||||||||||||||||||||||||||
| 627 | 64 | foreach my $path ($progpath, "$progpath/lib") | |||||||||||||||||||||||||||
| 628 | { | ||||||||||||||||||||||||||||
| 629 | # add new paths | ||||||||||||||||||||||||||||
| 630 | 128 | ▶ | unshift(@INC,$path) unless exists $inc{$path} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | 128 | $inc{$path} = 1 ; | |||||||||||||||||||||||||||
| 632 | 128 | ▶ | push @INC, $path unless exists $inc{$path} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | =item B<catch_error($error)> | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | Function that gets called on errors. $error is as defined in L<App::Framework::Base::Object::ErrorHandle> | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | =cut | ||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | sub catch_error | ||||||||||||||||||||||||||||
| 645 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
catch_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 646 | 1 | my $this = shift ; | |||||||||||||||||||||||||||
| 647 | 1 | my ($error) = @_ ; | |||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | # Does nothing! | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | 1 | $this->_dispatch_entry_features($error) ; | |||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 1 | $this->_dispatch_exit_features($error) ; | |||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | =item B<install_features($feature_list [, $feature_args])> | ||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | Add the listed features to the application. List is an ARRAY ref list of feature names. | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | Note: names need correct capitalisation (e.g. Sql not sql) - or just use first char capitalised(?) | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | Method/feature name will be all lowercase | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | Optionally, can specify I<$feature_args> HASH ref. Each feature name in I<$feature_list> should be a key | ||||||||||||||||||||||||||||
| 669 | in the HASH, the value of which is an arguments string (which is a list of feature arguments separated by space and/or | ||||||||||||||||||||||||||||
| 670 | commas) | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | =cut | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | sub install_features | ||||||||||||||||||||||||||||
| 675 | 56 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_features: called CC=15 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||
| 676 | 56 | my $this = shift ; | |||||||||||||||||||||||||||
| 677 | 56 | my ($feature_list, $feature_args_href) = @_ ; | |||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | 56 | ▶ | $feature_args_href ||= {} ; | ||||||||||||||||||||||||||
|
Condition100%2/2
$feature_args_href ||= {}
MC/DC100%1/1
$feature_args_href ||= {}
$feature_args_href
Truth table100%2/2
A
A= $feature_args_href
| |||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | 56 | my $features_href = $this->_feature_list() ; | |||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | ## make a list of features | ||||||||||||||||||||||||||||
| 684 | 56 | my @features = @$feature_list ; | |||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||
| 686 | 56 | $this->_dbg_prt(["install_features()", \@features, "features args=", $feature_args_href]) ; | |||||||||||||||||||||||||||
| 687 | 56 | ▶ | $class_debug = $this->debug if $this->debug >= 5 ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | ## Now try to install them | ||||||||||||||||||||||||||||
| 691 | 56 | foreach my $feature (@features) | |||||||||||||||||||||||||||
| 692 | { | ||||||||||||||||||||||||||||
| 693 | 150 | ▶ | my $feature_args = $feature_args_href->{$feature} || "" ; | ||||||||||||||||||||||||||
|
Condition100%2/2
$feature_args_href->{$feature} || ''
MC/DC100%1/1
$feature_args_href->{$feature} || ''
$feature_args_href->{$feature}
Truth table100%2/2
A
A= $feature_args_href->{$feature}
| |||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | 150 | my $loaded ; | |||||||||||||||||||||||||||
| 696 | 150 | my $feature_guess = ucfirst(lc($feature)) ; | |||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | ## skip if already loaded | ||||||||||||||||||||||||||||
| 699 | 150 | ▶ | if (exists($features_href->{$feature}) || exists($features_href->{$feature_guess})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $features_href->{$feature} or exists $features_href->{$feature_guess}
MC/DC0%0/2
exists $features_href->{$feature} or exists $features_href->{$feature_guess}
exists $features_href->{$feature}
exists $features_href->{$feature_guess}
Truth table33%1/3
A or B
A= exists $features_href->{$feature}B= exists $features_href->{$feature_guess}
| |||||||||||||||||||||||||||||
| 700 | { | ||||||||||||||||||||||||||||
| 701 | ## Just need to see if we've got any new args | ||||||||||||||||||||||||||||
| 702 | 0 | foreach my $feat ($feature, $feature_guess) | |||||||||||||||||||||||||||
| 703 | { | ||||||||||||||||||||||||||||
| 704 | 0 | ▶ | if (exists($feature_args_href->{$feat})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 705 | { | ||||||||||||||||||||||||||||
| 706 | ## override args | ||||||||||||||||||||||||||||
| 707 | 0 | my $feature_obj = $features_href->{$feature}{'object'} ; | |||||||||||||||||||||||||||
| 708 | 0 | $feature_obj->feature_args($feature_args_href->{$feat}) ; | |||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||
| 711 | 0 | next ; | |||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | # build list of module names to attempt. If personality name is set, try looking for feature | ||||||||||||||||||||||||||||
| 715 | # under personality subdir first. This allows for personality override of feature (e.g. POE:app overrides Script:app) | ||||||||||||||||||||||||||||
| 716 | # | ||||||||||||||||||||||||||||
| 717 | 150 | my @tries ; | |||||||||||||||||||||||||||
| 718 | 150 | my $personality = $this->personality ; | |||||||||||||||||||||||||||
| 719 | 150 | my $root = "App::Framework::Feature" ; | |||||||||||||||||||||||||||
| 720 | 150 | ▶ | if ($personality) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 721 | { | ||||||||||||||||||||||||||||
| 722 | 150 | push @tries, "${root}::${personality}::$feature" ; | |||||||||||||||||||||||||||
| 723 | 150 | push @tries, "${root}::${personality}::$feature_guess" ; | |||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||
| 725 | 150 | push @tries, "${root}::$feature" ; | |||||||||||||||||||||||||||
| 726 | 150 | push @tries, "${root}::$feature_guess" ; | |||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | 150 | foreach my $module (@tries) | |||||||||||||||||||||||||||
| 729 | { | ||||||||||||||||||||||||||||
| 730 | 465 | ▶ | if ($this->dynamic_load($module)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 731 | { | ||||||||||||||||||||||||||||
| 732 | 150 | $loaded = $module ; | |||||||||||||||||||||||||||
| 733 | 150 | last ; | |||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | 150 | my $cwd = cwd() ; | |||||||||||||||||||||||||||
| 738 | 150 | ▶ | $this->_dbg_prt(["Feature: $feature - unable to load. CWD=$cwd.\n", "Tried=", \@tries, "\n\@INC=", \@INC]) unless ($loaded) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | 150 | ▶ | croak "Feature \"$feature\" not supported" unless ($loaded) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | 150 | $this->_dbg_prt(["Feature: $feature - loaded=$loaded\n"]) ; | |||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||
| 744 | 150 | ▶ | if ($loaded) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 745 | { | ||||||||||||||||||||||||||||
| 746 | # save in list | ||||||||||||||||||||||||||||
| 747 | 150 | my $module = $loaded ; | |||||||||||||||||||||||||||
| 748 | 150 | my $specified_name = $feature ; | |||||||||||||||||||||||||||
| 749 | 150 | $feature = lc $feature ; | |||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | 150 | $features_href->{$feature} = { | |||||||||||||||||||||||||||
| 752 | 'module' => $module, # loaded module name | ||||||||||||||||||||||||||||
| 753 | 'specified' => $specified_name, # as specified by user | ||||||||||||||||||||||||||||
| 754 | 'name' => $feature, # name used as a method | ||||||||||||||||||||||||||||
| 755 | 'object' => undef, | ||||||||||||||||||||||||||||
| 756 | 'priority' => $App::Framework::Base::PRIORITY_DEFAULT, | ||||||||||||||||||||||||||||
| 757 | } ; | ||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | # see if we have some extra init values to pass to the feature | ||||||||||||||||||||||||||||
| 760 | 150 | my $feature_init_href = $this->_feature_init($feature) ; | |||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||
| 762 | # create feature | ||||||||||||||||||||||||||||
| 763 | my $feature_obj = $module->new( | ||||||||||||||||||||||||||||
| 764 | %$feature_init_href, | ||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | 'app' => $this, | ||||||||||||||||||||||||||||
| 767 | 'name' => $feature, # ensure it matches with what the app expects | ||||||||||||||||||||||||||||
| 768 | 'feature_args' => $feature_args, | ||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | # Set up error handler | ||||||||||||||||||||||||||||
| 771 | 1 | ▶ | 'catch_fn' => sub {$this->catch_error(@_);}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||
| 773 | 150 | ) ; | |||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||
| 775 | # add to list (may already have been done if feature registers any methods) | ||||||||||||||||||||||||||||
| 776 | 150 | $features_href->{$feature}{'object'} = $feature_obj ; | |||||||||||||||||||||||||||
| 777 | 150 | $features_href->{$feature}{'priority'} = $feature_obj->priority ; | |||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | # set up alias | ||||||||||||||||||||||||||||
| 780 | { | ||||||||||||||||||||||||||||
| 781 | 35 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 782 | 35 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||
| 784 | ## alias <feature>() | ||||||||||||||||||||||||||||
| 785 | 150 | my $alias = lc $feature ; | |||||||||||||||||||||||||||
| 786 | 150 | ▶ | *{"App::Framework::Core::${alias}"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 787 | 757 | my $this = shift ; | |||||||||||||||||||||||||||
| 788 | 757 | return $feature_obj->$alias(@_) ; | |||||||||||||||||||||||||||
| 789 | 150 | }; | |||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||
| 791 | ## alias <Feature>() | ||||||||||||||||||||||||||||
| 792 | 150 | $alias = ucfirst $feature ; | |||||||||||||||||||||||||||
| 793 | 150 | ▶ | *{"App::Framework::Core::${alias}"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 794 | 52 | my $this = shift ; | |||||||||||||||||||||||||||
| 795 | 52 | return $feature_obj->$alias(@_) ; | |||||||||||||||||||||||||||
| 796 | 150 | }; | |||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||
| 802 | ## Ensure list is sorted by priority | ||||||||||||||||||||||||||||
| 803 | 56 | $this->feature_list( [ sort {$features_href->{$a}{'priority'} <=> $features_href->{$b}{'priority'}} keys %$features_href ] ) ; | |||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||
| 806 | 56 | $this->_dbg_prt(["installed features = ", $features_href]) ; | |||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||
| 811 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 812 | # | ||||||||||||||||||||||||||||
| 813 | #=item B<_feature_init($feature)> | ||||||||||||||||||||||||||||
| 814 | # | ||||||||||||||||||||||||||||
| 815 | #Get any initialisation values for this feature. Returns an empty HASH ref if no | ||||||||||||||||||||||||||||
| 816 | #init specified | ||||||||||||||||||||||||||||
| 817 | # | ||||||||||||||||||||||||||||
| 818 | #=cut | ||||||||||||||||||||||||||||
| 819 | # | ||||||||||||||||||||||||||||
| 820 | sub _feature_init | ||||||||||||||||||||||||||||
| 821 | 150 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_feature_init: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 822 | 150 | my $this = shift ; | |||||||||||||||||||||||||||
| 823 | 150 | my ($feature) = @_ ; | |||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||
| 825 | 150 | my $feature_init_href = {} ; | |||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | ## May have some initialisation values for the feature | ||||||||||||||||||||||||||||
| 828 | 150 | my $feature_config_href = $this->feature_config ; | |||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||
| 830 | ## See if we can find a name match | ||||||||||||||||||||||||||||
| 831 | 150 | foreach my $name (keys %$feature_config_href) | |||||||||||||||||||||||||||
| 832 | { | ||||||||||||||||||||||||||||
| 833 | 52 | ▶ | if (lc $name eq lc $feature) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 834 | { | ||||||||||||||||||||||||||||
| 835 | 14 | $feature_init_href = $feature_config_href->{$name} ; | |||||||||||||||||||||||||||
| 836 | #$this->prt_data("_feature_init($feature)=", $feature_init_href) ; | ||||||||||||||||||||||||||||
| 837 | 14 | last ; | |||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | 150 | return $feature_init_href ; | |||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||
| 844 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 845 | # | ||||||||||||||||||||||||||||
| 846 | #=item B<feature_list()> | ||||||||||||||||||||||||||||
| 847 | # | ||||||||||||||||||||||||||||
| 848 | #Return list of installed features | ||||||||||||||||||||||||||||
| 849 | # | ||||||||||||||||||||||||||||
| 850 | #=cut | ||||||||||||||||||||||||||||
| 851 | # | ||||||||||||||||||||||||||||
| 852 | #sub feature_list | ||||||||||||||||||||||||||||
| 853 | #{ | ||||||||||||||||||||||||||||
| 854 | # my $this = shift ; | ||||||||||||||||||||||||||||
| 855 | # | ||||||||||||||||||||||||||||
| 856 | # my $features_href = $this->_feature_list() ; | ||||||||||||||||||||||||||||
| 857 | # my @list = map {$features_href->{$_}{'specified'}} keys %$features_href ; | ||||||||||||||||||||||||||||
| 858 | # return @list ; | ||||||||||||||||||||||||||||
| 859 | #} | ||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||
| 861 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 862 | # | ||||||||||||||||||||||||||||
| 863 | #=item B<_feature_info($name)> | ||||||||||||||||||||||||||||
| 864 | # | ||||||||||||||||||||||||||||
| 865 | #Return HASH ref of feature information for this feature. | ||||||||||||||||||||||||||||
| 866 | # | ||||||||||||||||||||||||||||
| 867 | #=cut | ||||||||||||||||||||||||||||
| 868 | # | ||||||||||||||||||||||||||||
| 869 | sub _feature_info | ||||||||||||||||||||||||||||
| 870 | 1098 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_feature_info: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 871 | 1098 | my $this = shift ; | |||||||||||||||||||||||||||
| 872 | 1098 | my ($name, %args) = @_ ; | |||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||
| 874 | 1098 | my $features_href = $this->_feature_list() ; | |||||||||||||||||||||||||||
| 875 | 1098 | $name = lc $name ; | |||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | 1098 | my $info_href ; | |||||||||||||||||||||||||||
| 878 | 1098 | ▶ | if (exists($features_href->{$name})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 879 | { | ||||||||||||||||||||||||||||
| 880 | 1098 | $info_href = $features_href->{$name} ; | |||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||
| 882 | else | ||||||||||||||||||||||||||||
| 883 | { | ||||||||||||||||||||||||||||
| 884 | 0 | $this->throw_fatal("Feature \"$name\" not found") ; | |||||||||||||||||||||||||||
| 885 | } | ||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||
| 887 | 1098 | return $info_href ; | |||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||
| 890 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||
| 892 | =item B<feature_installed($name)> | ||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||
| 894 | Return named feature object if the feature is installed; otherwise returns undef. | ||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||
| 896 | =cut | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | sub feature_installed | ||||||||||||||||||||||||||||
| 899 | 15 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
feature_installed: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 900 | 15 | my $this = shift ; | |||||||||||||||||||||||||||
| 901 | 15 | my ($name) = @_ ; | |||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | 15 | my $features_href = $this->_feature_list() ; | |||||||||||||||||||||||||||
| 904 | 15 | $name = lc $name ; | |||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||
| 906 | 15 | my $feature = undef ; | |||||||||||||||||||||||||||
| 907 | 15 | ▶ | if (exists($features_href->{$name})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 908 | { | ||||||||||||||||||||||||||||
| 909 | 5 | my $feature_href = $features_href->{$name} ; | |||||||||||||||||||||||||||
| 910 | 5 | $feature = $feature_href->{'object'} ; | |||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||
| 913 | 15 | return $feature ; | |||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||
| 918 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||
| 920 | =item B<feature($name [, %args])> | ||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||
| 922 | Return named feature object. Alternative interface to just calling the feature's 'get/set' method. | ||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||
| 924 | For example, 'sql' feature can be accessed either as: | ||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||
| 926 | my $sql = $app->feature("sql") ; | ||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||
| 928 | or: | ||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||
| 930 | my $sql = $app->sql() ; | ||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||
| 933 | =cut | ||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | sub feature | ||||||||||||||||||||||||||||
| 936 | 996 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
feature: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 937 | 996 | my $this = shift ; | |||||||||||||||||||||||||||
| 938 | 996 | my ($name, %args) = @_ ; | |||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||
| 940 | 996 | my $feature_href = $this->_feature_info($name) ; | |||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | 996 | my $feature = $feature_href->{'object'} ; | |||||||||||||||||||||||||||
| 943 | 996 | ▶ | if (%args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 944 | { | ||||||||||||||||||||||||||||
| 945 | 0 | $feature->set(%args) ; | |||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||
| 948 | 996 | return $feature ; | |||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||
| 952 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||
| 954 | =item B<feature_register($feature, $feature_obj, @function_list)> | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | API for feature objects. Used so that they can register their methods to be called | ||||||||||||||||||||||||||||
| 957 | at the start and end of the registered functions. | ||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||
| 959 | Function list is a list of strings where the string is in the format: | ||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||
| 961 | <method name>_entry | ||||||||||||||||||||||||||||
| 962 | <method_name>_exit | ||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||
| 964 | To register a call at the start of the method and/or at the end of the method. | ||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||
| 966 | This is usually called when the feature is being created (which is usually because this Core object | ||||||||||||||||||||||||||||
| 967 | is installing the feature). To ensure the core's lists are up to date, this function sets the feature object | ||||||||||||||||||||||||||||
| 968 | and priority. | ||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||
| 970 | =cut | ||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||
| 972 | sub feature_register | ||||||||||||||||||||||||||||
| 973 | 67 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
feature_register: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 974 | 67 | my $this = shift ; | |||||||||||||||||||||||||||
| 975 | 67 | my ($feature, $feature_obj, @function_list) = @_ ; | |||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||
| 977 | ## Add methods | ||||||||||||||||||||||||||||
| 978 | 67 | my $feature_methods_href = $this->_feature_methods() ; | |||||||||||||||||||||||||||
| 979 | 67 | foreach my $method (@function_list) | |||||||||||||||||||||||||||
| 980 | { | ||||||||||||||||||||||||||||
| 981 | 102 | my $feature_href = $this->_feature_info($feature) ; | |||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||
| 983 | # update info (ensure's core has latest info) | ||||||||||||||||||||||||||||
| 984 | 102 | $feature_href->{'object'} = $feature_obj ; | |||||||||||||||||||||||||||
| 985 | 102 | $feature_href->{'priority'} = $feature_obj->priority ; | |||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||
| 987 | #$this->prt_data("Feature info=", $feature_href); | ||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||
| 989 | 102 | ▶ | $feature_methods_href->{$method} ||= [] ; | ||||||||||||||||||||||||||
|
Condition100%2/2
$feature_methods_href->{$method} ||= []
MC/DC100%1/1
$feature_methods_href->{$method} ||= []
$feature_methods_href->{$method}
Truth table100%2/2
A
A= $feature_methods_href->{$method}
| |||||||||||||||||||||||||||||
| 990 | 102 | push @{$feature_methods_href->{$method}}, { | |||||||||||||||||||||||||||
| 991 | 'feature' => $feature, | ||||||||||||||||||||||||||||
| 992 | 'obj' => $feature_href->{'object'}, | ||||||||||||||||||||||||||||
| 993 | 102 | 'priority' => $feature_href->{'priority'}, | |||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||
| 998 | #$this->prt_data("Raw feature list=", $feature_methods_href); | ||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||
| 1000 | ## Ensure all lists are sorted by priority | ||||||||||||||||||||||||||||
| 1001 | 67 | foreach my $method (@function_list) | |||||||||||||||||||||||||||
| 1002 | { | ||||||||||||||||||||||||||||
| 1003 | 102 | $feature_methods_href->{$method} = [ sort {$a->{'priority'} <=> $b->{'priority'}} @{$feature_methods_href->{$method}} ] ; | |||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||
| 1006 | #$this->prt_data("Sorted feature list=", $feature_methods_href); | ||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||
| 1011 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1012 | # | ||||||||||||||||||||||||||||
| 1013 | #=item B<_dispatch_features($method, 'entry|exit')> | ||||||||||||||||||||||||||||
| 1014 | # | ||||||||||||||||||||||||||||
| 1015 | #INTERNAL: For the specified method, run any features that registered for this method. | ||||||||||||||||||||||||||||
| 1016 | # | ||||||||||||||||||||||||||||
| 1017 | #=cut | ||||||||||||||||||||||||||||
| 1018 | # | ||||||||||||||||||||||||||||
| 1019 | sub _dispatch_features | ||||||||||||||||||||||||||||
| 1020 | 1408 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dispatch_features: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 1021 | 1408 | my $this = shift ; | |||||||||||||||||||||||||||
| 1022 | 1408 | my ($method, $status, @args) = @_ ; | |||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||
| 1024 | 1408 | ▶ | @args = () unless @args ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1025 | 1408 | $this->_dbg_prt(["_dispatch_features(method=$method, status=$status) : args=", \@args]) ; | |||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||
| 1027 | # remove package name (if specified) | ||||||||||||||||||||||||||||
| 1028 | 1408 | $method =~ s/^(.*)::// ; | |||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||
| 1030 | 1408 | my $feature_methods_href = $this->_feature_methods() ; | |||||||||||||||||||||||||||
| 1031 | 1408 | my $fn = "${method}_${status}" ; | |||||||||||||||||||||||||||
| 1032 | 1408 | $this->_dbg_prt([" + method=$method fn=$fn\n"]) ; | |||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||
| 1034 | 1408 | ▶ | if (exists($feature_methods_href->{$fn})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1035 | { | ||||||||||||||||||||||||||||
| 1036 | 84 | foreach my $feature_entry (@{$feature_methods_href->{$fn}}) | |||||||||||||||||||||||||||
| 1037 | { | ||||||||||||||||||||||||||||
| 1038 | 129 | $this->_dbg_prt([" + dispatching fn=$fn feature=$feature_entry->{feature}\n"]) ; | |||||||||||||||||||||||||||
| 1039 | 129 | $this->_dbg_prt(["++ entry=", $feature_entry], 2) ; | |||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | 129 | my $feature_obj = $feature_entry->{'obj'} ; | |||||||||||||||||||||||||||
| 1042 | 129 | $feature_obj->$fn(@args) ; | |||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||
| 1044 | } | ||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||
| 1048 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1049 | # | ||||||||||||||||||||||||||||
| 1050 | #=item B<_dispatch_entry_features(@args)> | ||||||||||||||||||||||||||||
| 1051 | # | ||||||||||||||||||||||||||||
| 1052 | #INTERNAL: Calls _dispatch_features with the correct method name, and $status='entry' | ||||||||||||||||||||||||||||
| 1053 | # | ||||||||||||||||||||||||||||
| 1054 | #=cut | ||||||||||||||||||||||||||||
| 1055 | # | ||||||||||||||||||||||||||||
| 1056 | sub _dispatch_entry_features | ||||||||||||||||||||||||||||
| 1057 | 217 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dispatch_entry_features: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1058 | 217 | my $this = shift ; | |||||||||||||||||||||||||||
| 1059 | 217 | my (@args) = @_ ; | |||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||
| 1061 | 217 | my $method = (caller(1))[3] ; | |||||||||||||||||||||||||||
| 1062 | 217 | return $this->_dispatch_features($method, 'entry', @_) ; | |||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||
| 1066 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1067 | # | ||||||||||||||||||||||||||||
| 1068 | #=item B<_dispatch_exit_features(@args)> | ||||||||||||||||||||||||||||
| 1069 | # | ||||||||||||||||||||||||||||
| 1070 | #INTERNAL: Calls _dispatch_features with the correct method name, and $status='exit' | ||||||||||||||||||||||||||||
| 1071 | # | ||||||||||||||||||||||||||||
| 1072 | #=cut | ||||||||||||||||||||||||||||
| 1073 | # | ||||||||||||||||||||||||||||
| 1074 | sub _dispatch_exit_features | ||||||||||||||||||||||||||||
| 1075 | 201 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dispatch_exit_features: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1076 | 201 | my $this = shift ; | |||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||
| 1078 | 201 | my $method = (caller(1))[3] ; | |||||||||||||||||||||||||||
| 1079 | 201 | return $this->_dispatch_features($method, 'exit', @_) ; | |||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||
| 1083 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1084 | # | ||||||||||||||||||||||||||||
| 1085 | #=item B<_dispatch_label_entry_features($label, @args)> | ||||||||||||||||||||||||||||
| 1086 | # | ||||||||||||||||||||||||||||
| 1087 | #INTERNAL: Calls _dispatch_features with the correct method name, and $status='entry' | ||||||||||||||||||||||||||||
| 1088 | # | ||||||||||||||||||||||||||||
| 1089 | #=cut | ||||||||||||||||||||||||||||
| 1090 | # | ||||||||||||||||||||||||||||
| 1091 | sub _dispatch_label_entry_features | ||||||||||||||||||||||||||||
| 1092 | 495 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dispatch_label_entry_features: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 1093 | 495 | my $this = shift ; | |||||||||||||||||||||||||||
| 1094 | 495 | my ($label, @args) = @_ ; | |||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||
| 1096 | 495 | my $method = (caller(1))[3] ; | |||||||||||||||||||||||||||
| 1097 | 495 | ▶ | $method .= "_$label" if $label ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1098 | 495 | return $this->_dispatch_features($method, 'entry', @args) ; | |||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||
| 1102 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1103 | # | ||||||||||||||||||||||||||||
| 1104 | #=item B<_dispatch_label_exit_features($label, @args)> | ||||||||||||||||||||||||||||
| 1105 | # | ||||||||||||||||||||||||||||
| 1106 | #INTERNAL: Calls _dispatch_features with the correct method name, and $status='exit' | ||||||||||||||||||||||||||||
| 1107 | # | ||||||||||||||||||||||||||||
| 1108 | #=cut | ||||||||||||||||||||||||||||
| 1109 | # | ||||||||||||||||||||||||||||
| 1110 | sub _dispatch_label_exit_features | ||||||||||||||||||||||||||||
| 1111 | 495 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dispatch_label_exit_features: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 1112 | 495 | my $this = shift ; | |||||||||||||||||||||||||||
| 1113 | 495 | my ($label, @args) = @_ ; | |||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||
| 1115 | 495 | my $method = (caller(1))[3] ; | |||||||||||||||||||||||||||
| 1116 | 495 | ▶ | $method .= "_$label" if $label ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1117 | 495 | return $this->_dispatch_features($method, 'exit', @args) ; | |||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||
| 1122 | #= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||
| 1124 | =back | ||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||
| 1126 | =head3 Application execution methods | ||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||
| 1128 | =over 4 | ||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | =cut | ||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||
| 1135 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||
| 1137 | =item B<go()> | ||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||
| 1139 | Execute the application. | ||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||
| 1141 | Calls the following methods in turn: | ||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||
| 1143 | * app_start | ||||||||||||||||||||||||||||
| 1144 | * application | ||||||||||||||||||||||||||||
| 1145 | * app_end | ||||||||||||||||||||||||||||
| 1146 | * exit | ||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||
| 1148 | =cut | ||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||
| 1151 | sub go | ||||||||||||||||||||||||||||
| 1152 | 41 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
go: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1153 | 41 | my $this = shift ; | |||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||
| 1155 | 41 | $this->_dispatch_entry_features() ; | |||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||
| 1157 | 41 | $this->app_start() ; | |||||||||||||||||||||||||||
| 1158 | 41 | $this->application() ; | |||||||||||||||||||||||||||
| 1159 | 33 | $this->app_end() ; | |||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||
| 1161 | 33 | $this->_dispatch_exit_features() ; | |||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||
| 1163 | 33 | $this->exit(0) ; | |||||||||||||||||||||||||||
| 1164 | } | ||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||
| 1166 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||
| 1168 | =item B<getopts()> | ||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||
| 1170 | Convert the (already processed) options list into settings. | ||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||
| 1172 | Returns result of calling GetOptions | ||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||
| 1174 | =cut | ||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||
| 1176 | sub getopts | ||||||||||||||||||||||||||||
| 1177 | 41 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
getopts: called CC=8 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||
| 1178 | 41 | my $this = shift ; | |||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||
| 1180 | 41 | $this->_dispatch_entry_features() ; | |||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||
| 1182 | # Parse options using GetOpts | ||||||||||||||||||||||||||||
| 1183 | 41 | my $opt = $this->feature('Options') ; | |||||||||||||||||||||||||||
| 1184 | 41 | my $args = $this->feature('Args') ; | |||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||
| 1186 | 41 | my $ok = $opt->get_options() ; | |||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||
| 1188 | # If ok, get any specified filenames | ||||||||||||||||||||||||||||
| 1189 | 41 | ▶ | if ($ok) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1190 | { | ||||||||||||||||||||||||||||
| 1191 | # Get args | ||||||||||||||||||||||||||||
| 1192 | 41 | my $arglist = $args->get_args() ; | |||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||
| 1194 | 41 | $this->_dbg_prt(["getopts() : arglist=", $arglist], 2) ; | |||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||
| 1197 | ## Expand vars | ||||||||||||||||||||||||||||
| 1198 | 41 | my %values ; | |||||||||||||||||||||||||||
| 1199 | 41 | my ($opt_values_href, $opt_defaults_href) = $opt->option_values_hash() ; | |||||||||||||||||||||||||||
| 1200 | 41 | my ($args_values_href) = $args->args_values_hash() ; | |||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||
| 1202 | 41 | %values = (%$opt_values_href) ; | |||||||||||||||||||||||||||
| 1203 | 41 | my %args_clash ; | |||||||||||||||||||||||||||
| 1204 | 41 | foreach my $key (keys %$args_values_href) | |||||||||||||||||||||||||||
| 1205 | { | ||||||||||||||||||||||||||||
| 1206 | 73 | ▶ | if (exists($values{$key})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1207 | { | ||||||||||||||||||||||||||||
| 1208 | 0 | $args_clash{$key} = $args_values_href->{$key} ; | |||||||||||||||||||||||||||
| 1209 | } | ||||||||||||||||||||||||||||
| 1210 | else | ||||||||||||||||||||||||||||
| 1211 | { | ||||||||||||||||||||||||||||
| 1212 | 73 | $values{$key} = $args_values_href->{$key} ; | |||||||||||||||||||||||||||
| 1213 | } | ||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | 41 | my @vars ; | |||||||||||||||||||||||||||
| 1217 | 41 | my %app_vars = $this->vars ; | |||||||||||||||||||||||||||
| 1218 | 41 | push @vars, \%app_vars ; | |||||||||||||||||||||||||||
| 1219 | 41 | push @vars, \%ENV ; | |||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||
| 1221 | ## expand all vars | ||||||||||||||||||||||||||||
| 1222 | 41 | $this->expand_keys(\%values, \@vars) ; | |||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||
| 1224 | # set new values | ||||||||||||||||||||||||||||
| 1225 | 41 | foreach my $key (keys %$opt_values_href) | |||||||||||||||||||||||||||
| 1226 | { | ||||||||||||||||||||||||||||
| 1227 | 110 | $opt_values_href->{$key} = $values{$key} ; | |||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||
| 1229 | 41 | foreach my $key (keys %$args_values_href) | |||||||||||||||||||||||||||
| 1230 | { | ||||||||||||||||||||||||||||
| 1231 | 73 | $args_values_href->{$key} = $values{$key} ; | |||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||
| 1234 | ## handle any name clash | ||||||||||||||||||||||||||||
| 1235 | 41 | ▶ | if (keys %args_clash) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1236 | { | ||||||||||||||||||||||||||||
| 1237 | 0 | unshift @vars, \%values ; | |||||||||||||||||||||||||||
| 1238 | 0 | $this->expand_keys(\%args_clash, \@vars) ; | |||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||
| 1240 | # set new values | ||||||||||||||||||||||||||||
| 1241 | 0 | foreach my $key (keys %args_clash) | |||||||||||||||||||||||||||
| 1242 | { | ||||||||||||||||||||||||||||
| 1243 | 0 | $args_values_href->{$key} = $args_clash{$key} ; | |||||||||||||||||||||||||||
| 1244 | } | ||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||
| 1247 | ## update settings | ||||||||||||||||||||||||||||
| 1248 | 41 | $opt->option_values_set($opt_values_href, $opt_defaults_href) ; | |||||||||||||||||||||||||||
| 1249 | 41 | $args->args_values_set($args_values_href) ; | |||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||
| 1251 | 41 | $this->_dispatch_exit_features() ; | |||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||
| 1253 | 41 | return $ok ; | |||||||||||||||||||||||||||
| 1254 | } | ||||||||||||||||||||||||||||
| 1255 | |||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||
| 1257 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||
| 1259 | =item B<app_start()> | ||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||
| 1261 | Set up before running the application. | ||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||
| 1263 | Calls the following methods in turn: | ||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||
| 1265 | * getopts | ||||||||||||||||||||||||||||
| 1266 | * [internal _expand_vars method] | ||||||||||||||||||||||||||||
| 1267 | * options | ||||||||||||||||||||||||||||
| 1268 | * (Application registered 'app_start' function) | ||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||
| 1270 | =cut | ||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||
| 1273 | sub app_start | ||||||||||||||||||||||||||||
| 1274 | 41 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
app_start: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1275 | 41 | my $this = shift ; | |||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||
| 1277 | 41 | $this->_dispatch_entry_features() ; | |||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||
| 1279 | ## process the data | ||||||||||||||||||||||||||||
| 1280 | 41 | $this->feature('data')->process() ; | |||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||
| 1282 | ## allow features to add their options | ||||||||||||||||||||||||||||
| 1283 | 41 | my $features_aref = $this->feature_list() ; | |||||||||||||||||||||||||||
| 1284 | 41 | foreach my $feature (@$features_aref) | |||||||||||||||||||||||||||
| 1285 | { | ||||||||||||||||||||||||||||
| 1286 | 186 | my $feature_obj = $this->feature($feature) ; | |||||||||||||||||||||||||||
| 1287 | 186 | my $feature_options_aref = $feature_obj->feature_options() ; | |||||||||||||||||||||||||||
| 1288 | 186 | ▶ | if (@$feature_options_aref) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1289 | { | ||||||||||||||||||||||||||||
| 1290 | 86 | $this->feature('Options')->append_options($feature_options_aref, $feature_obj->class) ; | |||||||||||||||||||||||||||
| 1291 | } | ||||||||||||||||||||||||||||
| 1292 | } | ||||||||||||||||||||||||||||
| 1293 | |||||||||||||||||||||||||||||
| 1294 | ## Add user-defined options last | ||||||||||||||||||||||||||||
| 1295 | 41 | $this->feature('Data')->append_user_options() ; | |||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||
| 1298 | ## Get options | ||||||||||||||||||||||||||||
| 1299 | # NOTE: Need to do this here so that derived objects work properly | ||||||||||||||||||||||||||||
| 1300 | 41 | my $ret = $this->getopts() ; | |||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||
| 1302 | ## Expand any variables in the data | ||||||||||||||||||||||||||||
| 1303 | 41 | $this->_expand_vars() ; | |||||||||||||||||||||||||||
| 1304 | |||||||||||||||||||||||||||||
| 1305 | # Handle options errors here after expanding variables | ||||||||||||||||||||||||||||
| 1306 | 41 | ▶ | unless ($ret) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1307 | { | ||||||||||||||||||||||||||||
| 1308 | 0 | $this->usage('opt') ; | |||||||||||||||||||||||||||
| 1309 | 0 | $this->exit(1) ; | |||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||
| 1312 | # get options | ||||||||||||||||||||||||||||
| 1313 | 41 | my %options = $this->options() ; | |||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||
| 1315 | ## function | ||||||||||||||||||||||||||||
| 1316 | 41 | $this->_exec_fn('app_start', $this, \%options) ; | |||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||
| 1318 | 41 | $this->_dispatch_exit_features() ; | |||||||||||||||||||||||||||
| 1319 | |||||||||||||||||||||||||||||
| 1320 | } | ||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||
| 1323 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||
| 1325 | =item B<application()> | ||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||
| 1327 | Execute the application. | ||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||
| 1329 | Calls the following methods in turn: | ||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||
| 1331 | * (Application registered 'app' function) | ||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||
| 1334 | =cut | ||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||
| 1337 | sub application | ||||||||||||||||||||||||||||
| 1338 | 41 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
application: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1339 | 41 | my $this = shift ; | |||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||
| 1341 | 41 | $this->_dispatch_entry_features() ; | |||||||||||||||||||||||||||
| 1342 | |||||||||||||||||||||||||||||
| 1343 | ## Execute function | ||||||||||||||||||||||||||||
| 1344 | 39 | my %options = $this->options() ; | |||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||
| 1346 | ## Check args here (do this AFTER allowing derived objects/features a chance to check the options etc) | ||||||||||||||||||||||||||||
| 1347 | 39 | $this->feature("Args")->check_args() ; | |||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||
| 1349 | # get args | ||||||||||||||||||||||||||||
| 1350 | 33 | my %args = $this->feature("Args")->arg_hash() ; | |||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||
| 1352 | ## Run application function | ||||||||||||||||||||||||||||
| 1353 | 33 | $this->_exec_fn('app', $this, \%options, \%args) ; | |||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||
| 1355 | ## Close any open arguments | ||||||||||||||||||||||||||||
| 1356 | 33 | $this->feature("Args")->close_args() ; | |||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||
| 1359 | 33 | $this->_dispatch_exit_features() ; | |||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||
| 1361 | } | ||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||
| 1363 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1364 | |||||||||||||||||||||||||||||
| 1365 | =item B<app_end()> | ||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||
| 1367 | Tidy up after the application. | ||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||
| 1369 | Calls the following methods in turn: | ||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||
| 1371 | * (Application registered 'app_end' function) | ||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||
| 1374 | =cut | ||||||||||||||||||||||||||||
| 1375 | |||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||
| 1377 | sub app_end | ||||||||||||||||||||||||||||
| 1378 | 33 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
app_end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1379 | 33 | my $this = shift ; | |||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||
| 1381 | 33 | $this->_dispatch_entry_features() ; | |||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||
| 1383 | # get options | ||||||||||||||||||||||||||||
| 1384 | 33 | my %options = $this->options() ; | |||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||
| 1386 | ## Execute function | ||||||||||||||||||||||||||||
| 1387 | 33 | $this->_exec_fn('app_end', $this, \%options) ; | |||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||
| 1389 | 33 | $this->_dispatch_exit_features() ; | |||||||||||||||||||||||||||
| 1390 | } | ||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||
| 1393 | |||||||||||||||||||||||||||||
| 1394 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||
| 1396 | =item B<exit()> | ||||||||||||||||||||||||||||
| 1397 | |||||||||||||||||||||||||||||
| 1398 | Exit the application. | ||||||||||||||||||||||||||||
| 1399 | |||||||||||||||||||||||||||||
| 1400 | =cut | ||||||||||||||||||||||||||||
| 1401 | |||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||
| 1403 | sub exit | ||||||||||||||||||||||||||||
| 1404 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
exit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1405 | 0 | my $this = shift ; | |||||||||||||||||||||||||||
| 1406 | 0 | my ($exit_code) = @_ ; | |||||||||||||||||||||||||||
| 1407 | |||||||||||||||||||||||||||||
| 1408 | 0 | die "Expected generic exit to be overridden: exit code=$exit_code" ; | |||||||||||||||||||||||||||
| 1409 | } | ||||||||||||||||||||||||||||
| 1410 | |||||||||||||||||||||||||||||
| 1411 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1412 | |||||||||||||||||||||||||||||
| 1413 | =item B<usage()> | ||||||||||||||||||||||||||||
| 1414 | |||||||||||||||||||||||||||||
| 1415 | Show usage | ||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||
| 1417 | =cut | ||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||
| 1419 | sub usage | ||||||||||||||||||||||||||||
| 1420 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1421 | 8 | my $this = shift ; | |||||||||||||||||||||||||||
| 1422 | 8 | my ($level) = @_ ; | |||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||
| 1424 | 8 | $this->_dispatch_entry_features($level) ; | |||||||||||||||||||||||||||
| 1425 | 8 | $this->_exec_fn('usage', $this, $level) ; | |||||||||||||||||||||||||||
| 1426 | 8 | $this->_dispatch_exit_features($level) ; | |||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||
| 1428 | } | ||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||
| 1430 | #= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = | ||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||
| 1432 | =back | ||||||||||||||||||||||||||||
| 1433 | |||||||||||||||||||||||||||||
| 1434 | =head3 Utility methods | ||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||
| 1436 | =over 4 | ||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||
| 1438 | =cut | ||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||
| 1444 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1445 | |||||||||||||||||||||||||||||
| 1446 | =item B<file_split($fname)> | ||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||
| 1448 | Utility method | ||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||
| 1450 | Parses the filename and returns the full path, basename, and extension. | ||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||
| 1452 | Effectively does: | ||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||
| 1454 | $fname = File::Spec->rel2abs($fname) ; | ||||||||||||||||||||||||||||
| 1455 | ($path, $base, $ext) = fileparse($fname, '\.[^\.]+') ; | ||||||||||||||||||||||||||||
| 1456 | return ($path, $base, $ext) ; | ||||||||||||||||||||||||||||
| 1457 | |||||||||||||||||||||||||||||
| 1458 | =cut | ||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||
| 1460 | sub file_split | ||||||||||||||||||||||||||||
| 1461 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
file_split: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1462 | 0 | my $this = shift ; | |||||||||||||||||||||||||||
| 1463 | 0 | my ($fname) = @_ ; | |||||||||||||||||||||||||||
| 1464 | |||||||||||||||||||||||||||||
| 1465 | 0 | $fname = File::Spec->rel2abs($fname) ; | |||||||||||||||||||||||||||
| 1466 | 0 | my ($path, $base, $ext) = fileparse($fname, '\.[^\.]+') ; | |||||||||||||||||||||||||||
| 1467 | 0 | return ($path, $base, $ext) ; | |||||||||||||||||||||||||||
| 1468 | } | ||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||
| 1470 | |||||||||||||||||||||||||||||
| 1471 | ## ============================================================================================ | ||||||||||||||||||||||||||||
| 1472 | # | ||||||||||||||||||||||||||||
| 1473 | #=back | ||||||||||||||||||||||||||||
| 1474 | # | ||||||||||||||||||||||||||||
| 1475 | #=head2 PRIVATE METHODS | ||||||||||||||||||||||||||||
| 1476 | # | ||||||||||||||||||||||||||||
| 1477 | #=over 4 | ||||||||||||||||||||||||||||
| 1478 | # | ||||||||||||||||||||||||||||
| 1479 | #=cut | ||||||||||||||||||||||||||||
| 1480 | # | ||||||||||||||||||||||||||||
| 1481 | ## ============================================================================================ | ||||||||||||||||||||||||||||
| 1482 | |||||||||||||||||||||||||||||
| 1483 | |||||||||||||||||||||||||||||
| 1484 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1485 | # | ||||||||||||||||||||||||||||
| 1486 | #=item B<_exec_fn($function, @args)> | ||||||||||||||||||||||||||||
| 1487 | # | ||||||||||||||||||||||||||||
| 1488 | #Execute the registered function (if one is registered). Passes @args to the function. | ||||||||||||||||||||||||||||
| 1489 | # | ||||||||||||||||||||||||||||
| 1490 | #=cut | ||||||||||||||||||||||||||||
| 1491 | # | ||||||||||||||||||||||||||||
| 1492 | sub _exec_fn | ||||||||||||||||||||||||||||
| 1493 | 115 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_exec_fn: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 1494 | 115 | my $this = shift ; | |||||||||||||||||||||||||||
| 1495 | 115 | my ($fn, @args) = @_ ; | |||||||||||||||||||||||||||
| 1496 | |||||||||||||||||||||||||||||
| 1497 | # Append _fn to function name, get the function, and call it if it's defined | ||||||||||||||||||||||||||||
| 1498 | 115 | my $fn_name = "${fn}_fn" ; | |||||||||||||||||||||||||||
| 1499 | 115 | ▶ | my $sub = $this->$fn_name() || '' ; | ||||||||||||||||||||||||||
|
Condition100%2/2
$this->$fn_name || ''
MC/DC100%1/1
$this->$fn_name || ''
$this->$fn_name
Truth table100%2/2
A
A= $this->$fn_name
| |||||||||||||||||||||||||||||
| 1500 | |||||||||||||||||||||||||||||
| 1501 | 115 | $this->_dbg_prt(["_exec_fn($fn) this=$this fn=$fn_name sub=$sub\n"], 2) ; | |||||||||||||||||||||||||||
| 1502 | #$this->prt_data("_exec_fn($fn) args[1]=", \$args[1], "args[2]=",\$args[2]) ; | ||||||||||||||||||||||||||||
| 1503 | #if $this->debug()>=2 ; | ||||||||||||||||||||||||||||
| 1504 | |||||||||||||||||||||||||||||
| 1505 | 115 | ▶ | &$sub(@args) if $sub ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1506 | } | ||||||||||||||||||||||||||||
| 1507 | |||||||||||||||||||||||||||||
| 1508 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1509 | # | ||||||||||||||||||||||||||||
| 1510 | #=item B<_import()> | ||||||||||||||||||||||||||||
| 1511 | # | ||||||||||||||||||||||||||||
| 1512 | #Load modules into caller package namespace. | ||||||||||||||||||||||||||||
| 1513 | # | ||||||||||||||||||||||||||||
| 1514 | #=cut | ||||||||||||||||||||||||||||
| 1515 | # | ||||||||||||||||||||||||||||
| 1516 | sub _import | ||||||||||||||||||||||||||||
| 1517 | 31 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_import: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 1518 | 31 | my $this = shift ; | |||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||
| 1520 | 31 | my $package = $this->package() ; | |||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||
| 1522 | # Debug | ||||||||||||||||||||||||||||
| 1523 | 31 | ▶ | if ($this->debug()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1524 | { | ||||||||||||||||||||||||||||
| 1525 | 0 | ▶ | unless ($package eq 'main') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1526 | { | ||||||||||||||||||||||||||||
| 1527 | 0 | print "\n $package symbols:\n"; dumpvar($package) ; | |||||||||||||||||||||||||||
| 1528 | } | ||||||||||||||||||||||||||||
| 1529 | } | ||||||||||||||||||||||||||||
| 1530 | |||||||||||||||||||||||||||||
| 1531 | ## Load useful modules into caller package | ||||||||||||||||||||||||||||
| 1532 | 31 | my $code ; | |||||||||||||||||||||||||||
| 1533 | |||||||||||||||||||||||||||||
| 1534 | # Set of useful modules | ||||||||||||||||||||||||||||
| 1535 | 31 | foreach my $mod (@App::Framework::Settings::MODULES) | |||||||||||||||||||||||||||
| 1536 | { | ||||||||||||||||||||||||||||
| 1537 | 341 | $code .= "use $mod;" ; | |||||||||||||||||||||||||||
| 1538 | } | ||||||||||||||||||||||||||||
| 1539 | |||||||||||||||||||||||||||||
| 1540 | # Get modules into this namespace | ||||||||||||||||||||||||||||
| 1541 | 31 | foreach my $mod (@App::Framework::Settings::MODULES) | |||||||||||||||||||||||||||
| 1542 | { | ||||||||||||||||||||||||||||
| 1543 | 31 | ▶ | eval "use $mod;" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1544 | 341 | ▶ | if ($@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1545 | { | ||||||||||||||||||||||||||||
| 1546 | 0 | warn "Unable to load module $mod\n" ; | |||||||||||||||||||||||||||
| 1547 | } | ||||||||||||||||||||||||||||
| 1548 | else | ||||||||||||||||||||||||||||
| 1549 | { | ||||||||||||||||||||||||||||
| 1550 | 341 | ++$LOADED_MODULES{$mod} ; | |||||||||||||||||||||||||||
| 1551 | } | ||||||||||||||||||||||||||||
| 1552 | } | ||||||||||||||||||||||||||||
| 1553 | |||||||||||||||||||||||||||||
| 1554 | # Get modules into caller package namespace | ||||||||||||||||||||||||||||
| 1555 | 31 | ▶ | eval "package $package;\n$code\n" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1556 | # if ($@) | ||||||||||||||||||||||||||||
| 1557 | # { | ||||||||||||||||||||||||||||
| 1558 | # warn "Unable to load modules : $@\n" ; | ||||||||||||||||||||||||||||
| 1559 | # } | ||||||||||||||||||||||||||||
| 1560 | } | ||||||||||||||||||||||||||||
| 1561 | |||||||||||||||||||||||||||||
| 1562 | |||||||||||||||||||||||||||||
| 1563 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1564 | # | ||||||||||||||||||||||||||||
| 1565 | #=item B<_register_fn()> | ||||||||||||||||||||||||||||
| 1566 | # | ||||||||||||||||||||||||||||
| 1567 | #Register a function provided as a subroutine in the caller package as an app method | ||||||||||||||||||||||||||||
| 1568 | #in this object. | ||||||||||||||||||||||||||||
| 1569 | # | ||||||||||||||||||||||||||||
| 1570 | #Will only set the field value if it's not already set. | ||||||||||||||||||||||||||||
| 1571 | # | ||||||||||||||||||||||||||||
| 1572 | #=cut | ||||||||||||||||||||||||||||
| 1573 | # | ||||||||||||||||||||||||||||
| 1574 | sub _register_fn | ||||||||||||||||||||||||||||
| 1575 | 310 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_register_fn: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 1576 | 310 | my $this = shift ; | |||||||||||||||||||||||||||
| 1577 | 310 | my ($function, $alias) = @_ ; | |||||||||||||||||||||||||||
| 1578 | |||||||||||||||||||||||||||||
| 1579 | 310 | ▶ | $alias ||= $function ; | ||||||||||||||||||||||||||
|
Condition33%1/3
$alias ||= $function
MC/DC0%0/2
$alias ||= $function
$alias
$function
Truth table33%1/3
A ||= B
A= $aliasB= $function
| |||||||||||||||||||||||||||||
| 1580 | 310 | my $field ="${alias}_fn" ; | |||||||||||||||||||||||||||
| 1581 | |||||||||||||||||||||||||||||
| 1582 | 310 | ▶ | $this->_register_var('CODE', $function, $field) unless $this->$field() ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1583 | } | ||||||||||||||||||||||||||||
| 1584 | |||||||||||||||||||||||||||||
| 1585 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1586 | # | ||||||||||||||||||||||||||||
| 1587 | #=item B<_register_scalar($external_name, $field_name)> | ||||||||||||||||||||||||||||
| 1588 | # | ||||||||||||||||||||||||||||
| 1589 | #Read the value of a variable in the caller package and copy that value as a data field | ||||||||||||||||||||||||||||
| 1590 | #in this object. | ||||||||||||||||||||||||||||
| 1591 | # | ||||||||||||||||||||||||||||
| 1592 | #Will only set the field value if it's not already set. | ||||||||||||||||||||||||||||
| 1593 | # | ||||||||||||||||||||||||||||
| 1594 | #=cut | ||||||||||||||||||||||||||||
| 1595 | # | ||||||||||||||||||||||||||||
| 1596 | sub _register_scalar | ||||||||||||||||||||||||||||
| 1597 | 31 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_register_scalar: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 1598 | 31 | my $this = shift ; | |||||||||||||||||||||||||||
| 1599 | 31 | my ($external_name, $field_name) = @_ ; | |||||||||||||||||||||||||||
| 1600 | |||||||||||||||||||||||||||||
| 1601 | 31 | ▶ | $this->_register_var('SCALAR', $external_name, $field_name) unless $this->$field_name() ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1602 | } | ||||||||||||||||||||||||||||
| 1603 | |||||||||||||||||||||||||||||
| 1604 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1605 | # | ||||||||||||||||||||||||||||
| 1606 | #=item B<_register_var($type, $external_name, $field_name)> | ||||||||||||||||||||||||||||
| 1607 | # | ||||||||||||||||||||||||||||
| 1608 | #Read the value of a variable in the caller package and copy that value as a data field | ||||||||||||||||||||||||||||
| 1609 | #in this object. $type specifies the variable type: 'SCALAR', 'ARRAY', 'HASH', 'CODE' | ||||||||||||||||||||||||||||
| 1610 | # | ||||||||||||||||||||||||||||
| 1611 | #NOTE: This method overwrites the field value irrespective of whether it's already set. | ||||||||||||||||||||||||||||
| 1612 | # | ||||||||||||||||||||||||||||
| 1613 | #=cut | ||||||||||||||||||||||||||||
| 1614 | # | ||||||||||||||||||||||||||||
| 1615 | sub _register_var | ||||||||||||||||||||||||||||
| 1616 | 320 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_register_var: called CC=10 SCAR=24.3
| |||||||||||||||||||||||||||||
| 1617 | 320 | my $this = shift ; | |||||||||||||||||||||||||||
| 1618 | 320 | my ($type, $external_name, $field_name) = @_ ; | |||||||||||||||||||||||||||
| 1619 | |||||||||||||||||||||||||||||
| 1620 | 320 | my $package = $this->package() ; | |||||||||||||||||||||||||||
| 1621 | |||||||||||||||||||||||||||||
| 1622 | 320 | local (*alias); # a local typeglob | |||||||||||||||||||||||||||
| 1623 | |||||||||||||||||||||||||||||
| 1624 | 320 | $this->_dbg_prt(["_register_var($type, $external_name, $field_name)\n"], 2) ; | |||||||||||||||||||||||||||
| 1625 | |||||||||||||||||||||||||||||
| 1626 | # We want to get access to the stash corresponding to the package | ||||||||||||||||||||||||||||
| 1627 | # name | ||||||||||||||||||||||||||||
| 1628 | 35 | ▶ | no strict "vars" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1629 | 35 | ▶ | no strict "refs" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1630 | 320 | *stash = *{"${package}::"}; # Now %stash is the symbol table | |||||||||||||||||||||||||||
| 1631 | |||||||||||||||||||||||||||||
| 1632 | 320 | ▶ | if (exists($stash{$external_name})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1633 | { | ||||||||||||||||||||||||||||
| 1634 | 73 | *alias = $stash{$external_name} ; | |||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||
| 1636 | 73 | $this->_dbg_prt([" + found $external_name in $package\n"], 2) ; | |||||||||||||||||||||||||||
| 1637 | |||||||||||||||||||||||||||||
| 1638 | 73 | ▶ | if ($type eq 'SCALAR') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1639 | { | ||||||||||||||||||||||||||||
| 1640 | 31 | ▶ | if (defined($alias)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1641 | { | ||||||||||||||||||||||||||||
| 1642 | 26 | $this->set($field_name => $alias) ; | |||||||||||||||||||||||||||
| 1643 | } | ||||||||||||||||||||||||||||
| 1644 | } | ||||||||||||||||||||||||||||
| 1645 | 73 | ▶ | if ($type eq 'ARRAY') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1646 | { | ||||||||||||||||||||||||||||
| 1647 | # was - if (defined(@alias)) - removed due to "deprecated" warning | ||||||||||||||||||||||||||||
| 1648 | 0 | ▶ | if (@alias) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1649 | { | ||||||||||||||||||||||||||||
| 1650 | 0 | $this->set($field_name => \@alias) ; | |||||||||||||||||||||||||||
| 1651 | } | ||||||||||||||||||||||||||||
| 1652 | } | ||||||||||||||||||||||||||||
| 1653 | 73 | ▶ | if ($type eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 1654 | { | ||||||||||||||||||||||||||||
| 1655 | 0 | ▶ | if (%alias) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1656 | { | ||||||||||||||||||||||||||||
| 1657 | 0 | $this->set($field_name => \%alias) ; | |||||||||||||||||||||||||||
| 1658 | } | ||||||||||||||||||||||||||||
| 1659 | } | ||||||||||||||||||||||||||||
| 1660 | elsif ($type eq 'CODE') | ||||||||||||||||||||||||||||
| 1661 | { | ||||||||||||||||||||||||||||
| 1662 | 42 | ▶ | if (defined(&alias)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1663 | { | ||||||||||||||||||||||||||||
| 1664 | 42 | $this->_dbg_prt([" + + Set $type - $external_name as $field_name\n"], 2) ; | |||||||||||||||||||||||||||
| 1665 | 42 | $this->set($field_name => \&alias) ; | |||||||||||||||||||||||||||
| 1666 | } | ||||||||||||||||||||||||||||
| 1667 | } | ||||||||||||||||||||||||||||
| 1668 | |||||||||||||||||||||||||||||
| 1669 | } | ||||||||||||||||||||||||||||
| 1670 | } | ||||||||||||||||||||||||||||
| 1671 | |||||||||||||||||||||||||||||
| 1672 | |||||||||||||||||||||||||||||
| 1673 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1674 | # | ||||||||||||||||||||||||||||
| 1675 | #=item B<_expand_vars()> | ||||||||||||||||||||||||||||
| 1676 | # | ||||||||||||||||||||||||||||
| 1677 | #Run through some of the application variables/fields and expand any instances of variables embedded | ||||||||||||||||||||||||||||
| 1678 | #within the values. | ||||||||||||||||||||||||||||
| 1679 | # | ||||||||||||||||||||||||||||
| 1680 | #Example: | ||||||||||||||||||||||||||||
| 1681 | # | ||||||||||||||||||||||||||||
| 1682 | # __DATA_ | ||||||||||||||||||||||||||||
| 1683 | # | ||||||||||||||||||||||||||||
| 1684 | # [SYNOPSIS] | ||||||||||||||||||||||||||||
| 1685 | # | ||||||||||||||||||||||||||||
| 1686 | # $name [options] <rrd file(s)> | ||||||||||||||||||||||||||||
| 1687 | # | ||||||||||||||||||||||||||||
| 1688 | #Here the 'synopsis' field contains the $name field variable. This needs to be expanded to the value of $name. | ||||||||||||||||||||||||||||
| 1689 | # | ||||||||||||||||||||||||||||
| 1690 | #NOTE: Currently this will NOT cope with cross references (so, if in the above example $name also contains a variable | ||||||||||||||||||||||||||||
| 1691 | #then that variable may or may not be expanded before the synopsis field is processed) | ||||||||||||||||||||||||||||
| 1692 | # | ||||||||||||||||||||||||||||
| 1693 | # | ||||||||||||||||||||||||||||
| 1694 | #=cut | ||||||||||||||||||||||||||||
| 1695 | # | ||||||||||||||||||||||||||||
| 1696 | sub _expand_vars | ||||||||||||||||||||||||||||
| 1697 | 41 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_expand_vars: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 1698 | 41 | my $this = shift ; | |||||||||||||||||||||||||||
| 1699 | |||||||||||||||||||||||||||||
| 1700 | 41 | $this->_dbg_prt(["_expand_vars() - START\n"], 2) ; | |||||||||||||||||||||||||||
| 1701 | |||||||||||||||||||||||||||||
| 1702 | # Get hash of fields | ||||||||||||||||||||||||||||
| 1703 | 41 | my %fields = $this->vars() ; | |||||||||||||||||||||||||||
| 1704 | |||||||||||||||||||||||||||||
| 1705 | #$this->_dbg_prt([" + fields=", \%fields], 2) ; | ||||||||||||||||||||||||||||
| 1706 | |||||||||||||||||||||||||||||
| 1707 | # work through each field, create a list of those that have changed | ||||||||||||||||||||||||||||
| 1708 | 41 | my %changed ; | |||||||||||||||||||||||||||
| 1709 | 41 | foreach my $field (sort keys %fields) | |||||||||||||||||||||||||||
| 1710 | { | ||||||||||||||||||||||||||||
| 1711 | # Skip non-scalars | ||||||||||||||||||||||||||||
| 1712 | 1433 | ▶ | next if ref($fields{$field}) ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1713 | |||||||||||||||||||||||||||||
| 1714 | # First see if this contains a '$' | ||||||||||||||||||||||||||||
| 1715 | 852 | ▶ | $fields{$field} ||= "" ; | ||||||||||||||||||||||||||
|
Condition100%2/2
$fields{$field} ||= ""
MC/DC100%1/1
$fields{$field} ||= ""
$fields{$field}
Truth table100%2/2
A
A= $fields{$field}
| |||||||||||||||||||||||||||||
| 1716 | 852 | my $ix = index $fields{$field}, '$' ; | |||||||||||||||||||||||||||
| 1717 | 852 | ▶ | if ($ix >= 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1718 | { | ||||||||||||||||||||||||||||
| 1719 | 21 | $this->_dbg_prt([" + + $field = $fields{$field} : index=$ix\n"], 3) ; | |||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||
| 1721 | # Do replacement | ||||||||||||||||||||||||||||
| 1722 | 21 | $fields{$field} =~ s{ | |||||||||||||||||||||||||||
| 1723 | \$ # find a literal dollar sign | ||||||||||||||||||||||||||||
| 1724 | \{{0,1} # optional brace | ||||||||||||||||||||||||||||
| 1725 | (\w+) # find a "word" and store it in $1 | ||||||||||||||||||||||||||||
| 1726 | \}{0,1} # optional brace | ||||||||||||||||||||||||||||
| 1727 | }{ | ||||||||||||||||||||||||||||
| 1728 | 35 | ▶ | no strict 'refs'; # for $$1 below | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1729 | 21 | ▶ | if (defined $fields{$1}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1730 | 21 | $fields{$1}; # expand global variables only | |||||||||||||||||||||||||||
| 1731 | } else { | ||||||||||||||||||||||||||||
| 1732 | 0 | "\${$1}"; # leave it | |||||||||||||||||||||||||||
| 1733 | } | ||||||||||||||||||||||||||||
| 1734 | }egx; | ||||||||||||||||||||||||||||
| 1735 | |||||||||||||||||||||||||||||
| 1736 | |||||||||||||||||||||||||||||
| 1737 | 21 | $this->_dbg_prt([" + + + new = $fields{$field}\n"], 3) ; | |||||||||||||||||||||||||||
| 1738 | |||||||||||||||||||||||||||||
| 1739 | # Add to list | ||||||||||||||||||||||||||||
| 1740 | 21 | $changed{$field} = $fields{$field} ; | |||||||||||||||||||||||||||
| 1741 | } | ||||||||||||||||||||||||||||
| 1742 | } | ||||||||||||||||||||||||||||
| 1743 | |||||||||||||||||||||||||||||
| 1744 | 41 | $this->_dbg_prt([" + changed=", \%changed], 2) ; | |||||||||||||||||||||||||||
| 1745 | |||||||||||||||||||||||||||||
| 1746 | # If some have changed then set them | ||||||||||||||||||||||||||||
| 1747 | 41 | ▶ | if (keys %changed) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1748 | { | ||||||||||||||||||||||||||||
| 1749 | 21 | $this->_dbg_prt([" + + set changed\n"], 2) ; | |||||||||||||||||||||||||||
| 1750 | 21 | $this->set(%changed) ; | |||||||||||||||||||||||||||
| 1751 | } | ||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||
| 1753 | 41 | $this->_dbg_prt(["_expand_vars() - END\n"], 2) ; | |||||||||||||||||||||||||||
| 1754 | } | ||||||||||||||||||||||||||||
| 1755 | |||||||||||||||||||||||||||||
| 1756 | |||||||||||||||||||||||||||||
| 1757 | |||||||||||||||||||||||||||||
| 1758 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1759 | |||||||||||||||||||||||||||||
| 1760 | =item B<debug_prt($items_aref [, $min_debug])> | ||||||||||||||||||||||||||||
| 1761 | |||||||||||||||||||||||||||||
| 1762 | Print out the items in the $items_aref ARRAY ref iff the application's debug level is >0. | ||||||||||||||||||||||||||||
| 1763 | If $min_debug is specified, will only print out items if the application's debug level is >= $min_debug. | ||||||||||||||||||||||||||||
| 1764 | |||||||||||||||||||||||||||||
| 1765 | =cut | ||||||||||||||||||||||||||||
| 1766 | |||||||||||||||||||||||||||||
| 1767 | sub debug_prt | ||||||||||||||||||||||||||||
| 1768 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
debug_prt: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 1769 | 0 | my $this = shift ; | |||||||||||||||||||||||||||
| 1770 | 0 | my ($items_aref, $min_debug) = @_ ; | |||||||||||||||||||||||||||
| 1771 | |||||||||||||||||||||||||||||
| 1772 | 0 | ▶ | $min_debug ||= 1 ; | ||||||||||||||||||||||||||
|
Condition0%0/2
$min_debug ||= 1
MC/DC0%0/1
$min_debug ||= 1
$min_debug
Truth table0%0/2
A
A= $min_debug
| |||||||||||||||||||||||||||||
| 1773 | |||||||||||||||||||||||||||||
| 1774 | ## check debug level setting | ||||||||||||||||||||||||||||
| 1775 | 0 | ▶ | if ($this->options->option('debug') >= $min_debug) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1776 | { | ||||||||||||||||||||||||||||
| 1777 | 0 | $this->prt_data(@$items_aref) ; | |||||||||||||||||||||||||||
| 1778 | } | ||||||||||||||||||||||||||||
| 1779 | } | ||||||||||||||||||||||||||||
| 1780 | |||||||||||||||||||||||||||||
| 1781 | |||||||||||||||||||||||||||||
| 1782 | |||||||||||||||||||||||||||||
| 1783 | # ============================================================================================ | ||||||||||||||||||||||||||||
| 1784 | # PRIVATE FUNCTIONS | ||||||||||||||||||||||||||||
| 1785 | # ============================================================================================ | ||||||||||||||||||||||||||||
| 1786 | |||||||||||||||||||||||||||||
| 1787 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1788 | # | ||||||||||||||||||||||||||||
| 1789 | #=item B<_dumpisa(package)> | ||||||||||||||||||||||||||||
| 1790 | # | ||||||||||||||||||||||||||||
| 1791 | #Starting at I<package>, show the parents | ||||||||||||||||||||||||||||
| 1792 | # | ||||||||||||||||||||||||||||
| 1793 | #=cut | ||||||||||||||||||||||||||||
| 1794 | # | ||||||||||||||||||||||||||||
| 1795 | sub _dumpisa | ||||||||||||||||||||||||||||
| 1796 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dumpisa: not called CC=4 SCAR=22.5
| |||||||||||||||||||||||||||||
| 1797 | 35 | ▶ | no strict "vars" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1798 | 35 | ▶ | no strict "refs" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1799 | |||||||||||||||||||||||||||||
| 1800 | 0 | my ($packageName, $level) = @_; | |||||||||||||||||||||||||||
| 1801 | |||||||||||||||||||||||||||||
| 1802 | |||||||||||||||||||||||||||||
| 1803 | 0 | ▶ | if (!defined($level)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1804 | { | ||||||||||||||||||||||||||||
| 1805 | 0 | print "#### PACKAGE: $packageName ISA HIERARCHY ###########################\n" ; | |||||||||||||||||||||||||||
| 1806 | } | ||||||||||||||||||||||||||||
| 1807 | else | ||||||||||||||||||||||||||||
| 1808 | { | ||||||||||||||||||||||||||||
| 1809 | 0 | print " "x$level ; | |||||||||||||||||||||||||||
| 1810 | 0 | print "$packageName\n" ; | |||||||||||||||||||||||||||
| 1811 | } | ||||||||||||||||||||||||||||
| 1812 | |||||||||||||||||||||||||||||
| 1813 | 0 | foreach my $isa (@{"${packageName}::ISA"}) | |||||||||||||||||||||||||||
| 1814 | { | ||||||||||||||||||||||||||||
| 1815 | 0 | _dumpisa($isa, ++$level) ; | |||||||||||||||||||||||||||
| 1816 | } | ||||||||||||||||||||||||||||
| 1817 | |||||||||||||||||||||||||||||
| 1818 | |||||||||||||||||||||||||||||
| 1819 | 0 | ▶ | if (!defined($level)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1820 | { | ||||||||||||||||||||||||||||
| 1821 | 0 | print "######################################################\n" ; | |||||||||||||||||||||||||||
| 1822 | } | ||||||||||||||||||||||||||||
| 1823 | } | ||||||||||||||||||||||||||||
| 1824 | |||||||||||||||||||||||||||||
| 1825 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 1826 | # | ||||||||||||||||||||||||||||
| 1827 | #=item B<_dumpvar(package)> | ||||||||||||||||||||||||||||
| 1828 | # | ||||||||||||||||||||||||||||
| 1829 | #Dump out all of the symbols in package I<package> | ||||||||||||||||||||||||||||
| 1830 | # | ||||||||||||||||||||||||||||
| 1831 | #=cut | ||||||||||||||||||||||||||||
| 1832 | # | ||||||||||||||||||||||||||||
| 1833 | sub _dumpvar | ||||||||||||||||||||||||||||
| 1834 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_dumpvar: not called CC=6 SCAR=32.6
| |||||||||||||||||||||||||||||
| 1835 | 35 | ▶ | no strict "vars" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1836 | 36 | ▶ | no strict "refs" ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1837 | |||||||||||||||||||||||||||||
| 1838 | 0 | my ($packageName) = @_; | |||||||||||||||||||||||||||
| 1839 | |||||||||||||||||||||||||||||
| 1840 | 0 | print "#### PACKAGE: $packageName ###########################\n" ; | |||||||||||||||||||||||||||
| 1841 | |||||||||||||||||||||||||||||
| 1842 | 0 | local (*alias); # a local typeglob | |||||||||||||||||||||||||||
| 1843 | # We want to get access to the stash corresponding to the package | ||||||||||||||||||||||||||||
| 1844 | # name | ||||||||||||||||||||||||||||
| 1845 | 0 | *stash = *{"${packageName}::"}; # Now %stash is the symbol table | |||||||||||||||||||||||||||
| 1846 | 0 | $, = " "; # Output separator for print | |||||||||||||||||||||||||||
| 1847 | # Iterate through the symbol table, which contains glob values | ||||||||||||||||||||||||||||
| 1848 | # indexed by symbol names. | ||||||||||||||||||||||||||||
| 1849 | 0 | ▶ | while (($varName, $globValue) = each %stash) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1850 | 0 | print "$varName ============================= \n"; | |||||||||||||||||||||||||||
| 1851 | 0 | *alias = $globValue; | |||||||||||||||||||||||||||
| 1852 | 0 | ▶ | if (defined ($alias)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1853 | 0 | print "\t \$$varName $alias \n"; | |||||||||||||||||||||||||||
| 1854 | } | ||||||||||||||||||||||||||||
| 1855 | 0 | ▶ | if (@alias) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1856 | 0 | print "\t \@$varName @alias \n"; | |||||||||||||||||||||||||||
| 1857 | } | ||||||||||||||||||||||||||||
| 1858 | 0 | ▶ | if (%alias) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1859 | 0 | print "\t \%$varName ",%alias," \n"; | |||||||||||||||||||||||||||
| 1860 | } | ||||||||||||||||||||||||||||
| 1861 | 0 | ▶ | if (defined (&alias)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1862 | 0 | print "\t \&$varName \n"; | |||||||||||||||||||||||||||
| 1863 | } | ||||||||||||||||||||||||||||
| 1864 | } | ||||||||||||||||||||||||||||
| 1865 | |||||||||||||||||||||||||||||
| 1866 | 0 | print "######################################################\n" ; | |||||||||||||||||||||||||||
| 1867 | |||||||||||||||||||||||||||||
| 1868 | } | ||||||||||||||||||||||||||||
| 1869 | |||||||||||||||||||||||||||||
| 1870 | |||||||||||||||||||||||||||||
| 1871 | # ============================================================================================ | ||||||||||||||||||||||||||||
| 1872 | # END OF PACKAGE | ||||||||||||||||||||||||||||
| 1873 | |||||||||||||||||||||||||||||
| 1874 | =back | ||||||||||||||||||||||||||||
| 1875 | |||||||||||||||||||||||||||||
| 1876 | =head1 DIAGNOSTICS | ||||||||||||||||||||||||||||
| 1877 | |||||||||||||||||||||||||||||
| 1878 | Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages. | ||||||||||||||||||||||||||||
| 1879 | |||||||||||||||||||||||||||||
| 1880 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 1881 | |||||||||||||||||||||||||||||
| 1882 | Steve Price C<< <sdprice at cpan.org> >> | ||||||||||||||||||||||||||||
| 1883 | |||||||||||||||||||||||||||||
| 1884 | =head1 BUGS | ||||||||||||||||||||||||||||
| 1885 | |||||||||||||||||||||||||||||
| 1886 | None that I know of! | ||||||||||||||||||||||||||||
| 1887 | |||||||||||||||||||||||||||||
| 1888 | =cut | ||||||||||||||||||||||||||||
| 1889 | |||||||||||||||||||||||||||||
| 1890 | |||||||||||||||||||||||||||||
| 1891 | |||||||||||||||||||||||||||||
| 1892 | 34 | 1; | |||||||||||||||||||||||||||
| 1893 | |||||||||||||||||||||||||||||
| 1894 | __END__ | ||||||||||||||||||||||||||||