← Index
NYTProf Performance Profile   « line view »
For webmerge/scripts/webmerge.pl
  Run on Mon Oct 7 02:42:42 2013
Reported on Mon Oct 7 03:03:22 2013

Filename/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Embedder.pm
StatementsExecuted 42 statements in 7.13ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1115.67ms106msRTP::Webmerge::Embedder::::BEGIN@252RTP::Webmerge::Embedder::BEGIN@252
1115.38ms27.6msRTP::Webmerge::Embedder::::BEGIN@253RTP::Webmerge::Embedder::BEGIN@253
11196µs356µsRTP::Webmerge::Embedder::::BEGIN@8RTP::Webmerge::Embedder::BEGIN@8
11175µs75µsRTP::Webmerge::Embedder::::__ANON__[:75]RTP::Webmerge::Embedder::__ANON__[:75]
22270µs70µsRTP::Webmerge::Embedder::::registerRTP::Webmerge::Embedder::register
11160µs94µsRTP::Webmerge::Embedder::::BEGIN@10RTP::Webmerge::Embedder::BEGIN@10
11160µs242µsRTP::Webmerge::Embedder::::BEGIN@27RTP::Webmerge::Embedder::BEGIN@27
11159µs148µsRTP::Webmerge::Embedder::::BEGIN@9RTP::Webmerge::Embedder::BEGIN@9
11158µs334µsRTP::Webmerge::Embedder::::BEGIN@30RTP::Webmerge::Embedder::BEGIN@30
11156µs56µsRTP::Webmerge::Embedder::::BEGIN@18.23RTP::Webmerge::Embedder::BEGIN@18.23
11155µs533µsRTP::Webmerge::Embedder::::BEGIN@26RTP::Webmerge::Embedder::BEGIN@26
11129µs29µsRTP::Webmerge::Embedder::::BEGIN@21RTP::Webmerge::Embedder::BEGIN@21
11124µs24µsRTP::Webmerge::Embedder::::BEGIN@15RTP::Webmerge::Embedder::BEGIN@15
11123µs23µsRTP::Webmerge::Embedder::::BEGIN@18RTP::Webmerge::Embedder::BEGIN@18
0000s0sRTP::Webmerge::Embedder::::embedderRTP::Webmerge::Embedder::embedder
Call graph for these subroutines as a Graphviz dot language file.
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###################################################################################################
5package RTP::Webmerge::Embedder;
6###################################################################################################
7
82211µs2617µ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
use Carp;
# spent 356µs making 1 call to RTP::Webmerge::Embedder::BEGIN@8 # spent 260µs making 1 call to Exporter::import
92165µs2237µ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
use strict;
# spent 148µs making 1 call to RTP::Webmerge::Embedder::BEGIN@9 # spent 89µs making 1 call to strict::import
102198µs2128µ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
use warnings;
# 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
151152µs124µs
# spent 24µs within RTP::Webmerge::Embedder::BEGIN@15 which was called: # once (24µs+0s) by main::BEGIN@34 at line 15
BEGIN { $RTP::Webmerge::Embedder::VERSION = "0.70" }
# spent 24µs making 1 call to RTP::Webmerge::Embedder::BEGIN@15
16
17# load exporter and inherit from it
183366µs280µs
# spent 23µs within RTP::Webmerge::Embedder::BEGIN@18 which was called: # once (23µs+0s) by main::BEGIN@34 at line 18 # spent 56µs within RTP::Webmerge::Embedder::BEGIN@18.23 which was called: # once (56µs+0s) by main::BEGIN@34 at line 18
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
211153µs129µs
# spent 29µs within RTP::Webmerge::Embedder::BEGIN@21 which was called: # once (29µs+0s) by main::BEGIN@34 at line 21
BEGIN { our @EXPORT = qw(embedder); }
# spent 29µs making 1 call to RTP::Webmerge::Embedder::BEGIN@21
22
23###################################################################################################
24
25# load our local modules
262184µs21.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
use RTP::Webmerge qw(@initers);
# spent 533µs making 1 call to RTP::Webmerge::Embedder::BEGIN@26 # spent 478µs making 1 call to Exporter::import
272184µs2424µ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
use RTP::Webmerge::IO qw(writefile readfile);
# 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
3023.96ms2610µ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
use RTP::Webmerge::Path qw(dirname check_path exportURI importURI);
# spent 334µs making 1 call to RTP::Webmerge::Embedder::BEGIN@30 # spent 276µs making 1 call to Exporter::import
31
32###################################################################################################
33
3412µsour (%embedder, %tmpl);
35
36sub 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
39213µs my ($type, $embedder) = @_;
40
4127µs $type = lc $type;
42
4326µs if (exists $embedder{$type} && $embedder{$type} != $embedder)
44 { printf 'embedder type <%s> already registered', $type; exit; }
45
46285µs $embedder{$type} = $embedder;
47
48}
49# EO sub register
50
51# push to initers
52# return for getOpts
53push @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
5714µs my ($config) = @_;
58
59 # declare variables
6011µs my (@options);
61
62 # process each embedder type
63111µs foreach my $type (keys %embedder)
64 {
65 # create config variable to be available
66212µs $config->{'tmpl-embed-' . $type} = undef;
67 # connect each tmpl variable with the getOpt option
68211µs push(@options, 'tmpl-embed-' . $type . '=s'); # key
69221µs push(@options, \ $config->{'cmd_tmpl-embed-' . $type}); # value
70 }
71
72 # return getOpt options
73130µs return @options;
74
75118µs};
76# EO push initer
77
78###################################################################################################
79
80# create header include files
81# containing scripts/links nodes
82sub 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
2522705µs1106ms
# 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
use RTP::Webmerge::Embedder::JS;
# spent 106ms making 1 call to RTP::Webmerge::Embedder::BEGIN@252
2532610µs127.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
use RTP::Webmerge::Embedder::PHP;
# spent 27.6ms making 1 call to RTP::Webmerge::Embedder::BEGIN@253
254
255###################################################################################################
256####################################################################################################
257114µs1;