| 1 | package App::Framework::Feature ; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | App::Framework::Feature - Application feature | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | Features are accessed via the App::Framework object, for example: | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | use App::Framework '+Config' ; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | App::Framework::Feature is to be derived from and cannot be accessed directly. | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | Provides the base object from which all features must be derived. | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | B<DOCUMENTATION TO BE COMPLETED> | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 31 | ▶ | use strict ; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 31 | ▶ | use Carp ; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 31 | our $VERSION = "1.001" ; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | #============================================================================================ | ||||||||||||||||||||
| 30 | # USES | ||||||||||||||||||||
| 31 | #============================================================================================ | ||||||||||||||||||||
| 32 | 31 | ▶ | use App::Framework::Base ; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | #============================================================================================ | ||||||||||||||||||||
| 35 | # OBJECT HIERARCHY | ||||||||||||||||||||
| 36 | #============================================================================================ | ||||||||||||||||||||
| 37 | 31 | our @ISA = qw(App::Framework::Base) ; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | #============================================================================================ | ||||||||||||||||||||
| 40 | # GLOBALS | ||||||||||||||||||||
| 41 | #============================================================================================ | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head2 FIELDS | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | The following fields should be defined either in the call to 'new()', as part of a 'set()' call, or called by their accessor method | ||||||||||||||||||||
| 46 | (which is the same name as the field): | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =over 4 | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =item B<app> - Parent application | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | Set by App::Framework as a reference to the application object. If this is not set, then the feature will skip any application-specific | ||||||||||||||||||||
| 54 | logic (allowing a feature to be used in the user part of an application as a stand alone object). | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =item B<registered> - list of registered application functions | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | ARRAY ref to list of functions that this feature wants to register in the application. When a registered function is called by the framework, | ||||||||||||||||||||
| 59 | then the feature's method (of the same name) is also called. | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | Function name is of the form <name>_entry (called at the start of <name>) or <name>_exit (called at the end of <name>) | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =item B<name> - feature name | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | Set to the feature name (by the App::Framework). This is the name used by the application to access the feature | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =back | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 31 | my %FIELDS = ( | |||||||||||||||||||
| 72 | 'app' => undef, | ||||||||||||||||||||
| 73 | 'registered' => [], | ||||||||||||||||||||
| 74 | 'name' => 'feature', | ||||||||||||||||||||
| 75 | 'feature_args' => "", # Feature-specific arguments string | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 'feature_options' => [], | ||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | #============================================================================================ | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head2 CONSTRUCTOR | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =over 4 | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | #============================================================================================ | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =item B< new([%args]) > | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | Create a new feature. | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | The %args are specified as they would be in the B<set> method. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | sub new | ||||||||||||||||||||
| 99 | 151 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 100 | 151 | my ($obj, %args) = @_ ; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 151 | ▶ | 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
| |||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | # Create object | ||||||||||||||||||||
| 105 | 151 | my $this = $class->SUPER::new( | |||||||||||||||||||
| 106 | 'priority' => $App::Framework::Base::PRIORITY_DEFAULT, # will be overridden by derived object | ||||||||||||||||||||
| 107 | %args, | ||||||||||||||||||||
| 108 | ) ; | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | ## do application-specific bits | ||||||||||||||||||||
| 111 | 151 | $this->register_app() ; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 151 | return($this) ; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | #============================================================================================ | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =back | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head2 CLASS METHODS | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =over 4 | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | #============================================================================================ | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =item B< init_class([%args]) > | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | Initialises the object class variables. | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | sub init_class | ||||||||||||||||||||
| 139 | 151 | ▶ | { | ||||||||||||||||||
|
Subroutine
init_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 140 | 151 | my $class = shift ; | |||||||||||||||||||
| 141 | 151 | my (%args) = @_ ; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | # Add extra fields | ||||||||||||||||||||
| 144 | 151 | $class->add_fields(\%FIELDS, \%args) ; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | # init class | ||||||||||||||||||||
| 147 | 151 | $class->SUPER::init_class(%args) ; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =item B<allowed_class_instance()> | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | Returns 0 since this class can not have a class instance object | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | sub allowed_class_instance | ||||||||||||||||||||
| 160 | 151 | ▶ | { | ||||||||||||||||||
|
Subroutine
allowed_class_instance: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 161 | 151 | return 0 ; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | #============================================================================================ | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =back | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =head2 OBJECT DATA METHODS | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =over 4 | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | #============================================================================================ | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | ##----------------------------------------------------------------------------- | ||||||||||||||||||||
| 178 | # | ||||||||||||||||||||
| 179 | #=item B< feature_args([$args]) > | ||||||||||||||||||||
| 180 | # | ||||||||||||||||||||
| 181 | #Get/set the feature's arguments. If specified, I<$args> may be either an ARRAY ref (which is saved as-is), | ||||||||||||||||||||
| 182 | #or a SCALAR. In the case of the SCALAR, it is expected to be a space/comma separated list of argument | ||||||||||||||||||||
| 183 | #strings which are parsed and converted into an ARRAY ref | ||||||||||||||||||||
| 184 | # | ||||||||||||||||||||
| 185 | #=cut | ||||||||||||||||||||
| 186 | # | ||||||||||||||||||||
| 187 | #sub feature_args | ||||||||||||||||||||
| 188 | #{ | ||||||||||||||||||||
| 189 | # my $this = shift ; | ||||||||||||||||||||
| 190 | # my ($arg) = @_ ; | ||||||||||||||||||||
| 191 | # | ||||||||||||||||||||
| 192 | # if (defined($arg)) | ||||||||||||||||||||
| 193 | # { | ||||||||||||||||||||
| 194 | # if (ref($arg) eq 'ARRAY') | ||||||||||||||||||||
| 195 | # { | ||||||||||||||||||||
| 196 | # # use as-is | ||||||||||||||||||||
| 197 | # } | ||||||||||||||||||||
| 198 | # elsif (!ref($arg)) | ||||||||||||||||||||
| 199 | # { | ||||||||||||||||||||
| 200 | # # convert scalar | ||||||||||||||||||||
| 201 | # my @list ; | ||||||||||||||||||||
| 202 | # while ($arg =~ m/\s*([^\s,]+)[\s,]*/g) | ||||||||||||||||||||
| 203 | # { | ||||||||||||||||||||
| 204 | # push @list, $1 ; | ||||||||||||||||||||
| 205 | # } | ||||||||||||||||||||
| 206 | # | ||||||||||||||||||||
| 207 | # $arg = \@list ; | ||||||||||||||||||||
| 208 | # } | ||||||||||||||||||||
| 209 | # else | ||||||||||||||||||||
| 210 | # { | ||||||||||||||||||||
| 211 | # $arg = undef ; | ||||||||||||||||||||
| 212 | # } | ||||||||||||||||||||
| 213 | # } | ||||||||||||||||||||
| 214 | # | ||||||||||||||||||||
| 215 | # return $this->SUPER::feature_args($arg) ; | ||||||||||||||||||||
| 216 | #} | ||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | ##----------------------------------------------------------------------------- | ||||||||||||||||||||
| 220 | # | ||||||||||||||||||||
| 221 | #=item B< feature_args([$args]) > | ||||||||||||||||||||
| 222 | # | ||||||||||||||||||||
| 223 | #Get/set the feature's arguments. If specified, I<$args> may be either an ARRAY ref (which is saved as-is), | ||||||||||||||||||||
| 224 | #or a SCALAR. In the case of the SCALAR, it is expected to be a space/comma separated list of argument | ||||||||||||||||||||
| 225 | #strings which are parsed and converted into an ARRAY ref | ||||||||||||||||||||
| 226 | # | ||||||||||||||||||||
| 227 | #=cut | ||||||||||||||||||||
| 228 | # | ||||||||||||||||||||
| 229 | #sub feature_args | ||||||||||||||||||||
| 230 | #{ | ||||||||||||||||||||
| 231 | # my $this = shift ; | ||||||||||||||||||||
| 232 | # my ($arg) = @_ ; | ||||||||||||||||||||
| 233 | # | ||||||||||||||||||||
| 234 | #print "feature_args($arg) [$this]\n" ; | ||||||||||||||||||||
| 235 | #$this->dump_callstack() ; | ||||||||||||||||||||
| 236 | # | ||||||||||||||||||||
| 237 | # return $this->SUPER::feature_args($arg) ; | ||||||||||||||||||||
| 238 | #} | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | #============================================================================================ | ||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | =back | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | =head2 OBJECT METHODS | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | =over 4 | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | #============================================================================================ | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | |||||||||||||||||||||
| 253 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | =item B< register_app() > | ||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | Registers this feature with the parent application framework (if specified) | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | sub register_app | ||||||||||||||||||||
| 262 | 151 | ▶ | { | ||||||||||||||||||
|
Subroutine
register_app: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 263 | 151 | my $this = shift ; | |||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | 151 | my $app = $this->app ; | |||||||||||||||||||
| 266 | 151 | ▶ | if ($app) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 267 | { | ||||||||||||||||||||
| 268 | ## if we need to, register our methods with the application framework | ||||||||||||||||||||
| 269 | 150 | my $methods_aref = $this->registered ; | |||||||||||||||||||
| 270 | 150 | ▶ | if (@$methods_aref) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 271 | { | ||||||||||||||||||||
| 272 | 67 | $app->feature_register($this->name, $this, @$methods_aref) ; | |||||||||||||||||||
| 273 | } | ||||||||||||||||||||
| 274 | } | ||||||||||||||||||||
| 275 | } | ||||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | |||||||||||||||||||||
| 279 | # ============================================================================================ | ||||||||||||||||||||
| 280 | # END OF PACKAGE | ||||||||||||||||||||
| 281 | |||||||||||||||||||||
| 282 | =back | ||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | =head1 DIAGNOSTICS | ||||||||||||||||||||
| 285 | |||||||||||||||||||||
| 286 | Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages. | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | =head1 AUTHOR | ||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | Steve Price C<< <sdprice at cpan.org> >> | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | =head1 BUGS | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | None that I know of! | ||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | =cut | ||||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | 31 | 1; | |||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | __END__ | ||||||||||||||||||||