Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Embedder.pm |
Statements | Executed 42 statements in 7.13ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 5.67ms | 106ms | BEGIN@252 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 5.38ms | 27.6ms | BEGIN@253 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 96µs | 356µs | BEGIN@8 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 75µs | 75µs | __ANON__[:75] | RTP::Webmerge::Embedder::
2 | 2 | 2 | 70µs | 70µs | register | RTP::Webmerge::Embedder::
1 | 1 | 1 | 60µs | 94µs | BEGIN@10 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 60µs | 242µs | BEGIN@27 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 59µs | 148µs | BEGIN@9 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 58µs | 334µs | BEGIN@30 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 56µs | 56µs | BEGIN@18.23 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 55µs | 533µs | BEGIN@26 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 29µs | 29µs | BEGIN@21 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 24µs | 24µs | BEGIN@15 | RTP::Webmerge::Embedder::
1 | 1 | 1 | 23µs | 23µs | BEGIN@18 | RTP::Webmerge::Embedder::
0 | 0 | 0 | 0s | 0s | embedder | RTP::Webmerge::Embedder::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ################################################################################################### | ||||
2 | # Copyright 2013 by Marcel Greter | ||||
3 | # This file is part of Webmerge (GPL3) | ||||
4 | ################################################################################################### | ||||
5 | package RTP::Webmerge::Embedder; | ||||
6 | ################################################################################################### | ||||
7 | |||||
8 | 2 | 211µs | 2 | 617µs | # spent 356µs (96+260) within RTP::Webmerge::Embedder::BEGIN@8 which was called:
# once (96µs+260µs) by main::BEGIN@34 at line 8 # spent 356µs making 1 call to RTP::Webmerge::Embedder::BEGIN@8
# spent 260µs making 1 call to Exporter::import |
9 | 2 | 165µs | 2 | 237µs | # spent 148µs (59+89) within RTP::Webmerge::Embedder::BEGIN@9 which was called:
# once (59µs+89µs) by main::BEGIN@34 at line 9 # spent 148µs making 1 call to RTP::Webmerge::Embedder::BEGIN@9
# spent 89µs making 1 call to strict::import |
10 | 2 | 198µs | 2 | 128µs | # spent 94µs (60+33) within RTP::Webmerge::Embedder::BEGIN@10 which was called:
# once (60µs+33µs) by main::BEGIN@34 at line 10 # spent 94µs making 1 call to RTP::Webmerge::Embedder::BEGIN@10
# spent 34µs making 1 call to warnings::import |
11 | |||||
12 | ################################################################################################### | ||||
13 | |||||
14 | # define our version string | ||||
15 | 1 | 152µs | 1 | 24µs | # spent 24µs within RTP::Webmerge::Embedder::BEGIN@15 which was called:
# once (24µs+0s) by main::BEGIN@34 at line 15 # spent 24µs making 1 call to RTP::Webmerge::Embedder::BEGIN@15 |
16 | |||||
17 | # load exporter and inherit from it | ||||
18 | 3 | 366µs | 2 | 80µs | BEGIN { use Exporter qw(); our @ISA = qw(Exporter) } # spent 56µs making 1 call to RTP::Webmerge::Embedder::BEGIN@18.23
# spent 23µs making 1 call to RTP::Webmerge::Embedder::BEGIN@18 |
19 | |||||
20 | # define our functions to be exported | ||||
21 | 1 | 153µs | 1 | 29µs | # spent 29µs within RTP::Webmerge::Embedder::BEGIN@21 which was called:
# once (29µs+0s) by main::BEGIN@34 at line 21 # spent 29µs making 1 call to RTP::Webmerge::Embedder::BEGIN@21 |
22 | |||||
23 | ################################################################################################### | ||||
24 | |||||
25 | # load our local modules | ||||
26 | 2 | 184µs | 2 | 1.01ms | # spent 533µs (55+478) within RTP::Webmerge::Embedder::BEGIN@26 which was called:
# once (55µs+478µs) by main::BEGIN@34 at line 26 # spent 533µs making 1 call to RTP::Webmerge::Embedder::BEGIN@26
# spent 478µs making 1 call to Exporter::import |
27 | 2 | 184µs | 2 | 424µs | # spent 242µs (60+182) within RTP::Webmerge::Embedder::BEGIN@27 which was called:
# once (60µs+182µs) by main::BEGIN@34 at line 27 # spent 242µs making 1 call to RTP::Webmerge::Embedder::BEGIN@27
# spent 182µs making 1 call to Exporter::import |
28 | |||||
29 | # use core mdoules for path handling | ||||
30 | 2 | 3.96ms | 2 | 610µs | # spent 334µs (58+276) within RTP::Webmerge::Embedder::BEGIN@30 which was called:
# once (58µs+276µs) by main::BEGIN@34 at line 30 # spent 334µs making 1 call to RTP::Webmerge::Embedder::BEGIN@30
# spent 276µs making 1 call to Exporter::import |
31 | |||||
32 | ################################################################################################### | ||||
33 | |||||
34 | 1 | 2µs | our (%embedder, %tmpl); | ||
35 | |||||
36 | sub register | ||||
37 | # spent 70µs within RTP::Webmerge::Embedder::register which was called 2 times, avg 35µs/call:
# once (37µs+0s) by RTP::Webmerge::Embedder::BEGIN@252 at line 153 of webmerge/scripts/modules/RTP/Webmerge/Embedder/JS.pm
# once (33µs+0s) by RTP::Webmerge::Embedder::BEGIN@253 at line 145 of webmerge/scripts/modules/RTP/Webmerge/Embedder/PHP.pm | ||||
38 | |||||
39 | 2 | 13µs | my ($type, $embedder) = @_; | ||
40 | |||||
41 | 2 | 7µs | $type = lc $type; | ||
42 | |||||
43 | 2 | 6µs | if (exists $embedder{$type} && $embedder{$type} != $embedder) | ||
44 | { printf 'embedder type <%s> already registered', $type; exit; } | ||||
45 | |||||
46 | 2 | 85µs | $embedder{$type} = $embedder; | ||
47 | |||||
48 | } | ||||
49 | # EO sub register | ||||
50 | |||||
51 | # push to initers | ||||
52 | # return for getOpts | ||||
53 | push @initers, sub | ||||
54 | # spent 75µs within RTP::Webmerge::Embedder::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Embedder.pm:75] which was called:
# once (75µs+0s) by RTP::Webmerge::initConfig at line 263 of webmerge/scripts/modules/RTP/Webmerge.pm | ||||
55 | |||||
56 | # get config | ||||
57 | 1 | 4µs | my ($config) = @_; | ||
58 | |||||
59 | # declare variables | ||||
60 | 1 | 1µs | my (@options); | ||
61 | |||||
62 | # process each embedder type | ||||
63 | 1 | 11µs | foreach my $type (keys %embedder) | ||
64 | { | ||||
65 | # create config variable to be available | ||||
66 | 2 | 12µs | $config->{'tmpl-embed-' . $type} = undef; | ||
67 | # connect each tmpl variable with the getOpt option | ||||
68 | 2 | 11µs | push(@options, 'tmpl-embed-' . $type . '=s'); # key | ||
69 | 2 | 21µs | push(@options, \ $config->{'cmd_tmpl-embed-' . $type}); # value | ||
70 | } | ||||
71 | |||||
72 | # return getOpt options | ||||
73 | 1 | 30µs | return @options; | ||
74 | |||||
75 | 1 | 18µs | }; | ||
76 | # EO push initer | ||||
77 | |||||
78 | ################################################################################################### | ||||
79 | |||||
80 | # create header include files | ||||
81 | # containing scripts/links nodes | ||||
82 | sub embedder | ||||
83 | { | ||||
84 | |||||
85 | # get input variables | ||||
86 | my ($config, $embedder) = @_; | ||||
87 | |||||
88 | # get local variables from config | ||||
89 | my $atomic = $config->{'atomic'}; | ||||
90 | |||||
91 | # test if current header has been disabled | ||||
92 | return if exists $embedder->{'disabled'} && | ||||
93 | lc $embedder->{'disabled'} eq 'true'; | ||||
94 | |||||
95 | # get local variables from config | ||||
96 | # my $webpath = $config->{'webpath'}; | ||||
97 | # my $webroot = $config->{'webroot'}; | ||||
98 | |||||
99 | # collect information | ||||
100 | my (%features, %domains); | ||||
101 | |||||
102 | # collect all features and their detectors | ||||
103 | my $includes = $config->{'xml'}->{'headinc'}; | ||||
104 | my $features = $config->{'xml'}->{'feature'}; | ||||
105 | |||||
106 | # collect all features by names (reverse order) | ||||
107 | foreach my $feature (reverse @{$features || []}) | ||||
108 | { | ||||
109 | unless ( defined $feature->{'id'} ) | ||||
110 | { die 'feature without id found'; } | ||||
111 | $features{$feature->{'id'}} = $feature; | ||||
112 | } | ||||
113 | # EO each feature | ||||
114 | |||||
115 | # collect all includes by domain | ||||
116 | foreach my $include (@{$includes || []}) | ||||
117 | { | ||||
118 | |||||
119 | # change directory (restore previous state after this block) | ||||
120 | my $dir = RTP::Webmerge::Path->chdir($include->{'chdir'}); | ||||
121 | |||||
122 | # get variables from include | ||||
123 | my $id = $include->{'id'}; | ||||
124 | my $rootids = $include->{'rootid'}; | ||||
125 | |||||
126 | # rootid may contain a comma separated list | ||||
127 | foreach my $rootid (split(/\s*,\s*/, $rootids)) | ||||
128 | { | ||||
129 | |||||
130 | # create data structure for this domain entry | ||||
131 | $domains{$rootid} = { 'dev' => {}, 'live' => {} }; | ||||
132 | |||||
133 | # collect all outputs by context/class | ||||
134 | foreach my $output (@{$include->{'output'} || []}) | ||||
135 | { | ||||
136 | |||||
137 | # get variables from output | ||||
138 | my $class = $output->{'class'}; | ||||
139 | my $context = $output->{'context'}; | ||||
140 | |||||
141 | # store the absolute path to the output file for include | ||||
142 | $domains{$rootid}->{$context}->{$class} = check_path $output->{'path'}; | ||||
143 | |||||
144 | # remove leading webroot path for each include file | ||||
145 | # this will make the whole process better deployable | ||||
146 | # $domains{$rootid}->{$context}->{$class} =~ s/^\Q$webroot\E\/+//; | ||||
147 | |||||
148 | } | ||||
149 | # EO each output | ||||
150 | |||||
151 | } | ||||
152 | # EO each rootid | ||||
153 | |||||
154 | } | ||||
155 | # EO each include | ||||
156 | |||||
157 | # put the arrays into local variables | ||||
158 | my $detects = $embedder->{'detect'} || []; | ||||
159 | my $outputs = $embedder->{'output'} || []; | ||||
160 | |||||
161 | # process all output (different types) | ||||
162 | foreach my $output (@{$outputs || [] }) | ||||
163 | { | ||||
164 | |||||
165 | # get options for this output | ||||
166 | my $path = $output->{'path'}; | ||||
167 | my $types = $output->{'type'}; | ||||
168 | |||||
169 | # make lowercase | ||||
170 | $types = lc $types; | ||||
171 | |||||
172 | # resolve path to absolute path | ||||
173 | $path = check_path $path; | ||||
174 | |||||
175 | # create new hash so we can | ||||
176 | # manipulate it for this output | ||||
177 | my %includes; my %contents; | ||||
178 | |||||
179 | # load all include files content | ||||
180 | # to the generated embedder script | ||||
181 | foreach my $did (keys %domains) | ||||
182 | { | ||||
183 | # define new objects | ||||
184 | $includes{$did} = {}; | ||||
185 | $contents{$did} = {}; | ||||
186 | # process each context in domain id | ||||
187 | foreach my $context (keys %{$domains{$did}}) | ||||
188 | { | ||||
189 | # define new objects | ||||
190 | $includes{$did}->{$context} = {}; | ||||
191 | $contents{$did}->{$context} = {}; | ||||
192 | # process each class in domain id context | ||||
193 | foreach my $class (keys %{$domains{$did}->{$context}}) | ||||
194 | { | ||||
195 | # get the filepath to load/include | ||||
196 | my $file = $domains{$did}->{$context}->{$class}; | ||||
197 | # load the content of the include file | ||||
198 | my $data = readfile($file, $atomic); | ||||
199 | # make include paths relative to output | ||||
200 | $file = exportURI($file, dirname($path)); | ||||
201 | # assert that the file could be loaded | ||||
202 | die "could not load $file" unless defined $data; | ||||
203 | # store filepath and the content for later | ||||
204 | $includes{$did}->{$context}->{$class} = $file; | ||||
205 | $contents{$did}->{$context}->{$class} = ${$data}; | ||||
206 | } | ||||
207 | } | ||||
208 | } | ||||
209 | # EO foreach include | ||||
210 | |||||
211 | # types may be a comma separated list | ||||
212 | foreach my $type (split(/\s*\,\s*/, $types)) | ||||
213 | { | ||||
214 | |||||
215 | # check if embedder type is registered | ||||
216 | if (exists $embedder{$type}) | ||||
217 | { | ||||
218 | |||||
219 | # get the embedder code for this given type (i.e. php or perl) | ||||
220 | my $code = $embedder{lc$type}(\%includes, \%contents, \%features, $detects, $config); | ||||
221 | |||||
222 | # give debug message about creating the embedder code | ||||
223 | print "creating standalone embedder for $type\n"; | ||||
224 | |||||
225 | # write the include code now | ||||
226 | writefile($path, $code, $atomic); | ||||
227 | |||||
228 | # give a success message to the console | ||||
229 | print " created <", $output->{'path'}, ">\n"; | ||||
230 | |||||
231 | } | ||||
232 | else | ||||
233 | { | ||||
234 | |||||
235 | # die with an error if type is unknown | ||||
236 | # maybe you forgot to load the type module | ||||
237 | die "unknown embedder output type <$type>\n" | ||||
238 | |||||
239 | } | ||||
240 | |||||
241 | } | ||||
242 | |||||
243 | }; | ||||
244 | # EO each output | ||||
245 | |||||
246 | } | ||||
247 | # EO sub embedder | ||||
248 | |||||
249 | ################################################################################################### | ||||
250 | |||||
251 | # load implementations | ||||
252 | 2 | 705µs | 1 | 106ms | # spent 106ms (5.67+101) within RTP::Webmerge::Embedder::BEGIN@252 which was called:
# once (5.67ms+101ms) by main::BEGIN@34 at line 252 # spent 106ms making 1 call to RTP::Webmerge::Embedder::BEGIN@252 |
253 | 2 | 610µs | 1 | 27.6ms | # spent 27.6ms (5.38+22.2) within RTP::Webmerge::Embedder::BEGIN@253 which was called:
# once (5.38ms+22.2ms) by main::BEGIN@34 at line 253 # spent 27.6ms making 1 call to RTP::Webmerge::Embedder::BEGIN@253 |
254 | |||||
255 | ################################################################################################### | ||||
256 | #################################################################################################### | ||||
257 | 1 | 14µs | 1; |