← 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/HeadInc.pm
StatementsExecuted 25 statements in 6.19ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111154µs423µsRTP::Webmerge::HeadInc::::BEGIN@8RTP::Webmerge::HeadInc::BEGIN@8
11171µs71µsRTP::Webmerge::HeadInc::::BEGIN@18.22RTP::Webmerge::HeadInc::BEGIN@18.22
11159µs92µsRTP::Webmerge::HeadInc::::BEGIN@10RTP::Webmerge::HeadInc::BEGIN@10
11158µs362µsRTP::Webmerge::HeadInc::::BEGIN@26RTP::Webmerge::HeadInc::BEGIN@26
11158µs211µsRTP::Webmerge::HeadInc::::BEGIN@29RTP::Webmerge::HeadInc::BEGIN@29
11157µs216µsRTP::Webmerge::HeadInc::::BEGIN@28RTP::Webmerge::HeadInc::BEGIN@28
11155µs149µsRTP::Webmerge::HeadInc::::BEGIN@9RTP::Webmerge::HeadInc::BEGIN@9
11154µs516µsRTP::Webmerge::HeadInc::::BEGIN@34RTP::Webmerge::HeadInc::BEGIN@34
11126µs26µsRTP::Webmerge::HeadInc::::BEGIN@21RTP::Webmerge::HeadInc::BEGIN@21
11125µs25µsRTP::Webmerge::HeadInc::::BEGIN@15RTP::Webmerge::HeadInc::BEGIN@15
11123µs23µsRTP::Webmerge::HeadInc::::BEGIN@18RTP::Webmerge::HeadInc::BEGIN@18
11123µs23µsRTP::Webmerge::HeadInc::::__ANON__[:49]RTP::Webmerge::HeadInc::__ANON__[:49]
0000s0sRTP::Webmerge::HeadInc::::headincRTP::Webmerge::HeadInc::headinc
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::HeadInc;
6###################################################################################################
7
82203µs2692µs
# spent 423µs (154+269) within RTP::Webmerge::HeadInc::BEGIN@8 which was called: # once (154µs+269µs) by main::BEGIN@33 at line 8
use Carp;
# spent 423µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@8 # spent 269µs making 1 call to Exporter::import
92148µs2242µs
# spent 149µs (55+94) within RTP::Webmerge::HeadInc::BEGIN@9 which was called: # once (55µs+94µs) by main::BEGIN@33 at line 9
use strict;
# spent 149µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@9 # spent 94µs making 1 call to strict::import
102200µs2126µs
# spent 92µs (59+34) within RTP::Webmerge::HeadInc::BEGIN@10 which was called: # once (59µs+34µs) by main::BEGIN@33 at line 10
use warnings;
# spent 92µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@10 # spent 34µs making 1 call to warnings::import
11
12###################################################################################################
13
14# define our version string
151148µs125µs
# spent 25µs within RTP::Webmerge::HeadInc::BEGIN@15 which was called: # once (25µs+0s) by main::BEGIN@33 at line 15
BEGIN { $RTP::Webmerge::HeadInc::VERSION = "0.70" }
# spent 25µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@15
16
17# load exporter and inherit from it
183388µs294µs
# spent 71µs within RTP::Webmerge::HeadInc::BEGIN@18.22 which was called: # once (71µs+0s) by main::BEGIN@33 at line 18 # spent 23µs within RTP::Webmerge::HeadInc::BEGIN@18 which was called: # once (23µs+0s) by main::BEGIN@33 at line 18
BEGIN { use Exporter qw(); our @ISA = qw(Exporter) }
# spent 71µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@18.22 # spent 23µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@18
19
20# define our functions to be exported
211140µs126µs
# spent 26µs within RTP::Webmerge::HeadInc::BEGIN@21 which was called: # once (26µs+0s) by main::BEGIN@33 at line 21
BEGIN { our @EXPORT = qw(headinc); }
# spent 26µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@21
22
23###################################################################################################
24
25# make absolute paths
262191µs2666µs
# spent 362µs (58+304) within RTP::Webmerge::HeadInc::BEGIN@26 which was called: # once (58µs+304µs) by main::BEGIN@33 at line 26
use RTP::Webmerge::Path;
# spent 362µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@26 # spent 304µs making 1 call to Exporter::import
27
282166µs2375µs
# spent 216µs (57+159) within RTP::Webmerge::HeadInc::BEGIN@28 which was called: # once (57µs+159µs) by main::BEGIN@33 at line 28
use RTP::Webmerge::IO qw(writefile);
# spent 216µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@28 # spent 159µs making 1 call to Exporter::import
292177µs2364µs
# spent 211µs (58+153) within RTP::Webmerge::HeadInc::BEGIN@29 which was called: # once (58µs+153µs) by main::BEGIN@33 at line 29
use RTP::Webmerge::Fingerprint qw(fingerprint);
# spent 211µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@29 # spent 153µs making 1 call to Exporter::import
30
31###################################################################################################
32
33# import registered processors
3424.32ms2977µs
# spent 516µs (54+461) within RTP::Webmerge::HeadInc::BEGIN@34 which was called: # once (54µs+461µs) by main::BEGIN@33 at line 34
use RTP::Webmerge qw(@initers);
# spent 516µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@34 # spent 461µs making 1 call to Exporter::import
35
36# register initializer
37push @initers, sub
38
# spent 23µs within RTP::Webmerge::HeadInc::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/HeadInc.pm:49] which was called: # once (23µs+0s) by RTP::Webmerge::initConfig at line 263 of webmerge/scripts/modules/RTP/Webmerge.pm
{
39
40 # get input variables
4113µs my ($config) = @_;
42
43 # assign default value to variable
4415µs $config->{'jsdeferer'} = 'head.js';
45
46 # return additional get options attribute
47127µs return ( 'jsdeferer=s' => \ $config->{'cmd_jsdeferer'} );
48
49122µs};
50# EO plugin initer
51
52###################################################################################################
53
54# declare templates
55130µsmy $tmpl =
56{
57
58 'xhtml' =>
59 {
60 'js' => '<script type="text/javascript" src="%1$s"></script>',
61 'css' => '<link rel="stylesheet" type="text/css" href="%1$s"/>',
62 'script' => '<script type="text/javascript">%1$s</script>',
63 'jsdefer' => '<script type="text/javascript">%3$s({ \'%2$s\' : \'%1$s\' });</script>'
64 },
65
66 'html' =>
67 {
68 'js' => '<script type="text/javascript" src="%1$s"></script>',
69 'css' => '<link rel="stylesheet" type="text/css" href="%1$s">',
70 'script' => '<script type="text/javascript">%1$s</script>',
71 'jsdefer' => '<script type="text/javascript">%3$s({ \'%2$s\' : \'%1$s\' });</script>'
72 },
73
74 'html5' =>
75 {
76 'js' => '<script src="%1$s"></script>',
77 'css' => '<link rel="stylesheet" href="%1$s">',
78 'script' => '<script>%1$s</script>',
79 'jsdefer' => '<script>%3$s({ \'%2$s\' : \'%1$s\' });</script>'
80 }
81
82};
83
84###################################################################################################
85
86###################################################################################################
87
88# create header include files
89# containing scripts/links nodes
90sub headinc
91{
92
93 # get input variables
94 my ($config, $headinc) = @_;
95
96 # collect output paths
97 # collectOutputs($config);
98
99 # get local variables from config
100 my $atomic = $config->{'atomic'};
101 my $doctype = $config->{'doctype'};
102 my $incorder = $config->{'incorder'};
103 my $outpaths = $config->{'outpaths'};
104
105 # test if current header has been disabled
106 return if exists $headinc->{'disabled'} &&
107 lc $headinc->{'disabled'} eq 'true';
108
109 # put the arrays into local variables
110 my $inputs = $headinc->{'input'} || [];
111 my $outputs = $headinc->{'output'} || [];
112
113 # change directory (restore previous state after this block)
114 my $dir = RTP::Webmerge::Path->chdir($headinc->{'chdir'});
115
116 # process all header output entries
117 foreach my $output (@{$outputs || [] })
118 {
119
120 # collect includes
121 my @includes;
122
123 # get the class name for this output
124 my $class = $output->{'class'} || 'default';
125
126 # assert that the path has been given for this output
127 die 'no path given for output' unless $output->{'path'};
128 # assert that the context has been given for this output
129 die 'no context given for output' unless $output->{'context'};
130
131 print "creating header for class=", $class, " and context=", $output->{'context'}, "\n";
132
133 # get into local variable
134 my $path = $output->{'path'};
135 my $context = $output->{'context'};
136
137 # assert that context is a valid token
138 # I will choose the most appropriate include
139 unless ($context eq 'live' || $context eq 'dev')
140 { die 'context must be live or dev for head include'; }
141
142 # process all header input entries
143 foreach my $input (@{$inputs || [] })
144 {
145
146 # we have a text node
147 unless (ref($input))
148 {
149
150 # add text as is (you must not add script tags yourself)
151 push(@includes, sprintf $tmpl->{$doctype}->{'script'}, $input);
152
153 }
154
155 # source is given completely, just render include
156 elsif (exists $input->{'src'} && $input->{'src'})
157 {
158
159 # get local variables
160 my $id = $input->{'id'} || die "no id given for src head include";
161 my $type = $input->{'type'} || die "no type given for src head include";
162 my $incpath = $input->{'src'} || die "no src given for src head include";
163
164 # use special include if load is defered
165 my $defer = $input->{'defer'} || 'false';
166
167 # disable defering in dev mode
168 # XXX - find a way to use it anyway
169 $defer = 'false' if $context eq 'dev';
170
171 # get the include type wheter include is defered or not
172 my $inctype = lc $defer eq 'true' ? $type . 'defer' : $type;
173
174 # generate and add the include by using sprintf and the given template
175 push(@includes, sprintf $tmpl->{$doctype}->{$inctype}, $incpath, $id, $config->{'jsdeferer'});
176
177 }
178
179 # if we have an id we should include the file
180 elsif (exists $input->{'merged'} && $input->{'merged'})
181 {
182
183 # get into local variable
184 my $id = $input->{'merged'};
185
186 # assertion that the referenced id is a defined item
187 die "referenced input <$id> is invalid" unless exists $outpaths->{$id};
188
189 # get the media type for this input
190 my $type = $outpaths->{$id}->{'type'};
191
192 # use special include if load is defered
193 my $defer = $input->{'defer'} || 'false';
194
195 # disable defering in dev mode
196 # XXX - find a way to use it anyway
197 $defer = 'false' if $context eq 'dev';
198
199 # search the output path for this context
200 # will search all generated contexts for best match
201 my $outpath;
202
203 # classpaths to be searched
204 foreach my $classpaths
205 (
206 $outpaths->{$id}->{'out'}->{$class} || {},
207 $outpaths->{$id}->{'out'}->{'default'} || {}
208 )
209 {
210
211 # loop all targets from the include order
212 foreach my $target (@{$incorder->{$context}})
213 {
214
215 # skip this target if no output has been defined
216 next unless (exists $classpaths->{$target});
217
218 # assign the output path
219 $outpath = $classpaths->{$target};
220
221 # break if we have a valid one
222 last if defined $outpath;
223
224 }
225
226 # break if we have a valid one
227 last if defined $outpath;
228
229 }
230 # EO unless outpath
231
232 # assert that we have found a valid output file
233 die 'output path invalid for head include' unless $outpath;
234
235 # get the include type wheter include is defered or not
236 my $inctype = lc $defer eq 'true' ? $type . 'defer' : $type;
237
238 # add the fingerprint to the include path
239 # this include always uses query string technique
240 my $incpath = fingerprint($config, 'live', $outpath);
241
242 # remove hash tag and query string for URI
243 my $suffix = $incpath =~ s/([\;\?\#].*?)$// ? $1 : '';
244
245 # create the absolute web include path
246 $incpath = exportURI($outpath, undef, 1) . $suffix;
247
248 # generate and add the include by using sprintf and the given template
249 push(@includes, sprintf $tmpl->{$doctype}->{$inctype}, $incpath, $id, $config->{'jsdeferer'});
250
251 }
252
253 # otherwise we include the text node
254 else
255 {
256
257 # easy but not yet implemented
258 die "unsupported input configuration for headinc";
259
260 }
261
262 }
263 # EO each input
264
265 # create path to store this generated output
266 my $output_path = check_path $output->{'path'};
267
268 # create the include code to be written
269 my $output_code = join("\n", @includes) . "\n";
270
271 # write the include code now (atomic operation)
272 writefile($output_path, \ $output_code, $atomic);
273
274 # give a success message to the console
275 print " created <", $output->{'path'}, ">\n";
276
277 }
278 # EO each output
279
280}
281# EO sub headerIncludes
282
283###################################################################################################
284
285126µs1;