Filename | /var/www/foswikidev/core/lib/Foswiki/Configure/Pluggable.pm |
Statements | Executed 7 statements in 134µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 20µs | 33µs | BEGIN@49 | Foswiki::Configure::Pluggable::
1 | 1 | 1 | 10µs | 14µs | BEGIN@50 | Foswiki::Configure::Pluggable::
1 | 1 | 1 | 9µs | 38µs | BEGIN@52 | Foswiki::Configure::Pluggable::
0 | 0 | 0 | 0s | 0s | load | Foswiki::Configure::Pluggable::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package Foswiki::Configure::Pluggable | ||||
6 | |||||
7 | A Pluggable is a code module that generates items for a hard-coded block | ||||
8 | in a configuration, marked by *NAME* in the .spec. | ||||
9 | |||||
10 | Pluggables are used for blocks in the configuration that cannot be handled | ||||
11 | by the configuration abstraction, for example blocks used for | ||||
12 | downloading extensions, managing plugins, and managing languages. | ||||
13 | |||||
14 | A pluggable block will normally inject programatically | ||||
15 | generated configuration entries (subclasses of Foswiki::Configure::Item) into | ||||
16 | the configuration, usually by appending to the $open configuration item | ||||
17 | (which will normally be a Foswiki::Configure::Section). | ||||
18 | |||||
19 | Pluggable implementations are loaded by the parser by calling the | ||||
20 | =load= static method in this class. The implementations are packages | ||||
21 | in Foswiki::Configure::Pluggables, and must provide at least the following | ||||
22 | function: | ||||
23 | |||||
24 | ---++ StaticMethod construct( \@settings, $file, $line ) | ||||
25 | |||||
26 | Implemented by subclasses to create the pluggable. Pluggables are | ||||
27 | created in-place, by generating and adding Foswiki::Configure::Item | ||||
28 | objects and adding them to the settings array. | ||||
29 | |||||
30 | * =\@settings= - ref to the top level array of settings | ||||
31 | * =$file=, =$line= - file and line in the .spec that triggered the pluggable | ||||
32 | |||||
33 | Note that there is no need for constructors to worry about the hierarchical | ||||
34 | structure of .spec. The structure is only generated after all items have | ||||
35 | been generated, by analysis of section markers placed in the settings array. | ||||
36 | So items should be added by simply pushing them into @$settings. However, | ||||
37 | should a pluggable require a structure within the containing section, it is | ||||
38 | OK to push new =Foswiki::Configure::Section= objects to @$settings and | ||||
39 | populate them using =->addChild=. | ||||
40 | |||||
41 | Note also that values added by pluggables should *NOT* have defined_at | ||||
42 | set. The presence of this field is used to indicate whether a field was | ||||
43 | defined explicitly, or in a pluggable. | ||||
44 | |||||
45 | =cut | ||||
46 | |||||
47 | package Foswiki::Configure::Pluggable; | ||||
48 | |||||
49 | 2 | 29µs | 2 | 46µs | # spent 33µs (20+13) within Foswiki::Configure::Pluggable::BEGIN@49 which was called:
# once (20µs+13µs) by Foswiki::Configure::LoadSpec::BEGIN@66 at line 49 # spent 33µs making 1 call to Foswiki::Configure::Pluggable::BEGIN@49
# spent 13µs making 1 call to strict::import |
50 | 2 | 24µs | 2 | 18µs | # spent 14µs (10+4) within Foswiki::Configure::Pluggable::BEGIN@50 which was called:
# once (10µs+4µs) by Foswiki::Configure::LoadSpec::BEGIN@66 at line 50 # spent 14µs making 1 call to Foswiki::Configure::Pluggable::BEGIN@50
# spent 4µs making 1 call to warnings::import |
51 | |||||
52 | 2 | 79µs | 2 | 66µs | # spent 38µs (9+29) within Foswiki::Configure::Pluggable::BEGIN@52 which was called:
# once (9µs+29µs) by Foswiki::Configure::LoadSpec::BEGIN@66 at line 52 # spent 38µs making 1 call to Foswiki::Configure::Pluggable::BEGIN@52
# spent 29µs making 1 call to Exporter::import |
53 | |||||
54 | =begin TML | ||||
55 | |||||
56 | ---++ StaticMethod load($id) | ||||
57 | |||||
58 | Loads a pluggable section from =Foswiki::Configure::Pluggables::$id= | ||||
59 | |||||
60 | Will die if there's a problem. | ||||
61 | |||||
62 | Returns the result from the Pluggable class's =construct= | ||||
63 | |||||
64 | =cut | ||||
65 | |||||
66 | sub load { | ||||
67 | my $name = shift; | ||||
68 | |||||
69 | my $modelName = 'Foswiki::Configure::Pluggables::' . $name; | ||||
70 | eval("require $modelName; ${modelName}::construct(\@_);"); | ||||
71 | die $@ if $@; | ||||
72 | } | ||||
73 | |||||
74 | 1 | 2µs | 1; | ||
75 | __END__ |