File Coverage

blib/lib/App/Framework/Feature.pm
Criterion Covered Total %
statement 25 25 100.0
branch 4 4 100.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 4 4 100.0
total 41 43 95.3


line stmt bran cond sub pod time code
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
21              
22             =cut
23              
24 26     26   5068 use strict ;
  26         28  
  26         610  
25 26     26   79 use Carp ;
  26         30  
  26         1434  
26              
27             our $VERSION = "1.001" ;
28              
29             #============================================================================================
30             # USES
31             #============================================================================================
32 26     26   121 use App::Framework::Base ;
  26         28  
  26         6334  
33              
34             #============================================================================================
35             # OBJECT HIERARCHY
36             #============================================================================================
37             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 - 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 - 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 _entry (called at the start of ) or _exit (called at the end of )
62              
63             =item B - 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             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 method.
95              
96             =cut
97              
98             sub new
99             {
100 131     131 1 687 my ($obj, %args) = @_ ;
101              
102 131   33     731 my $class = ref($obj) || $obj ;
103              
104             # Create object
105 131         1483 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 131         899 $this->register_app() ;
112            
113 131         399 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             {
140 131     131 1 237 my $class = shift ;
141 131         481 my (%args) = @_ ;
142              
143             # Add extra fields
144 131         387 $class->add_fields(\%FIELDS, \%args) ;
145              
146             # init class
147 131         657 $class->SUPER::init_class(%args) ;
148              
149             }
150              
151             #----------------------------------------------------------------------------
152              
153             =item B
154              
155             Returns 0 since this class can not have a class instance object
156            
157             =cut
158              
159             sub allowed_class_instance
160             {
161 131     131 1 565 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             {
263 131     131 1 156 my $this = shift ;
264            
265 131         2615 my $app = $this->app ;
266 131 100       324 if ($app)
267             {
268             ## if we need to, register our methods with the application framework
269 130         2761 my $methods_aref = $this->registered ;
270 130 100       377 if (@$methods_aref)
271             {
272 57         1018 $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<< >>
291              
292             =head1 BUGS
293              
294             None that I know of!
295              
296             =cut
297              
298              
299             1;
300              
301             __END__