| Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/HeadInc.pm |
| Statements | Executed 25 statements in 6.19ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 154µs | 423µs | RTP::Webmerge::HeadInc::BEGIN@8 |
| 1 | 1 | 1 | 71µs | 71µs | RTP::Webmerge::HeadInc::BEGIN@18.22 |
| 1 | 1 | 1 | 59µs | 92µs | RTP::Webmerge::HeadInc::BEGIN@10 |
| 1 | 1 | 1 | 58µs | 362µs | RTP::Webmerge::HeadInc::BEGIN@26 |
| 1 | 1 | 1 | 58µs | 211µs | RTP::Webmerge::HeadInc::BEGIN@29 |
| 1 | 1 | 1 | 57µs | 216µs | RTP::Webmerge::HeadInc::BEGIN@28 |
| 1 | 1 | 1 | 55µs | 149µs | RTP::Webmerge::HeadInc::BEGIN@9 |
| 1 | 1 | 1 | 54µs | 516µs | RTP::Webmerge::HeadInc::BEGIN@34 |
| 1 | 1 | 1 | 26µs | 26µs | RTP::Webmerge::HeadInc::BEGIN@21 |
| 1 | 1 | 1 | 25µs | 25µs | RTP::Webmerge::HeadInc::BEGIN@15 |
| 1 | 1 | 1 | 23µs | 23µs | RTP::Webmerge::HeadInc::BEGIN@18 |
| 1 | 1 | 1 | 23µs | 23µs | RTP::Webmerge::HeadInc::__ANON__[:49] |
| 0 | 0 | 0 | 0s | 0s | RTP::Webmerge::HeadInc::headinc |
| 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::HeadInc; | ||||
| 6 | ################################################################################################### | ||||
| 7 | |||||
| 8 | 2 | 203µs | 2 | 692µ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 # spent 423µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@8
# spent 269µs making 1 call to Exporter::import |
| 9 | 2 | 148µs | 2 | 242µ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 # spent 149µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@9
# spent 94µs making 1 call to strict::import |
| 10 | 2 | 200µs | 2 | 126µ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 # 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 | ||||
| 15 | 1 | 148µs | 1 | 25µs | # spent 25µs within RTP::Webmerge::HeadInc::BEGIN@15 which was called:
# once (25µs+0s) by main::BEGIN@33 at line 15 # spent 25µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@15 |
| 16 | |||||
| 17 | # load exporter and inherit from it | ||||
| 18 | 3 | 388µs | 2 | 94µs | 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 | ||||
| 21 | 1 | 140µs | 1 | 26µs | # spent 26µs within RTP::Webmerge::HeadInc::BEGIN@21 which was called:
# once (26µs+0s) by main::BEGIN@33 at line 21 # spent 26µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@21 |
| 22 | |||||
| 23 | ################################################################################################### | ||||
| 24 | |||||
| 25 | # make absolute paths | ||||
| 26 | 2 | 191µs | 2 | 666µ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 # spent 362µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@26
# spent 304µs making 1 call to Exporter::import |
| 27 | |||||
| 28 | 2 | 166µs | 2 | 375µ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 # spent 216µs making 1 call to RTP::Webmerge::HeadInc::BEGIN@28
# spent 159µs making 1 call to Exporter::import |
| 29 | 2 | 177µs | 2 | 364µ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 # 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 | ||||
| 34 | 2 | 4.32ms | 2 | 977µ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 # 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 | ||||
| 37 | push @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 | ||||
| 41 | 1 | 3µs | my ($config) = @_; | ||
| 42 | |||||
| 43 | # assign default value to variable | ||||
| 44 | 1 | 5µs | $config->{'jsdeferer'} = 'head.js'; | ||
| 45 | |||||
| 46 | # return additional get options attribute | ||||
| 47 | 1 | 27µs | return ( 'jsdeferer=s' => \ $config->{'cmd_jsdeferer'} ); | ||
| 48 | |||||
| 49 | 1 | 22µs | }; | ||
| 50 | # EO plugin initer | ||||
| 51 | |||||
| 52 | ################################################################################################### | ||||
| 53 | |||||
| 54 | # declare templates | ||||
| 55 | 1 | 30µs | my $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 | ||||
| 90 | sub 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 | |||||
| 285 | 1 | 26µs | 1; |