| Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Optimize.pm |
| Statements | Executed 34 statements in 6.08ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 7 | 7 | 7 | 278µs | 278µs | RTP::Webmerge::Optimize::optimize |
| 1 | 1 | 1 | 113µs | 401µs | RTP::Webmerge::Optimize::BEGIN@84 |
| 1 | 1 | 1 | 92µs | 323µs | RTP::Webmerge::Optimize::BEGIN@87 |
| 1 | 1 | 1 | 89µs | 354µs | RTP::Webmerge::Optimize::BEGIN@11 |
| 1 | 1 | 1 | 83µs | 312µs | RTP::Webmerge::Optimize::BEGIN@90 |
| 1 | 1 | 1 | 57µs | 57µs | RTP::Webmerge::Optimize::BEGIN@26.24 |
| 1 | 1 | 1 | 56µs | 90µs | RTP::Webmerge::Optimize::BEGIN@13 |
| 1 | 1 | 1 | 52µs | 139µs | RTP::Webmerge::Optimize::BEGIN@12 |
| 1 | 1 | 1 | 30µs | 30µs | RTP::Webmerge::Optimize::BEGIN@29 |
| 1 | 1 | 1 | 29µs | 29µs | RTP::Webmerge::Optimize::BEGIN@32 |
| 1 | 1 | 1 | 24µs | 24µs | RTP::Webmerge::Optimize::BEGIN@23 |
| 1 | 1 | 1 | 24µs | 24µs | RTP::Webmerge::Optimize::BEGIN@26 |
| 0 | 0 | 0 | 0s | 0s | RTP::Webmerge::Optimize::__ANON__[:150] |
| 0 | 0 | 0 | 0s | 0s | RTP::Webmerge::Optimize::optimizer |
| 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 | # If you need to optimize other files, you may use this software | ||||
| 6 | # http://nikkhokkho.sourceforge.net/static.php?page=FileOptimizer | ||||
| 7 | ################################################################################################### | ||||
| 8 | package RTP::Webmerge::Optimize; | ||||
| 9 | ################################################################################################### | ||||
| 10 | |||||
| 11 | 2 | 165µs | 2 | 618µs | # spent 354µs (89+265) within RTP::Webmerge::Optimize::BEGIN@11 which was called:
# once (89µs+265µs) by main::BEGIN@35 at line 11 # spent 354µs making 1 call to RTP::Webmerge::Optimize::BEGIN@11
# spent 265µs making 1 call to Exporter::import |
| 12 | 2 | 146µs | 2 | 227µs | # spent 139µs (52+88) within RTP::Webmerge::Optimize::BEGIN@12 which was called:
# once (52µs+88µs) by main::BEGIN@35 at line 12 # spent 139µs making 1 call to RTP::Webmerge::Optimize::BEGIN@12
# spent 88µs making 1 call to strict::import |
| 13 | 2 | 255µs | 2 | 123µs | # spent 90µs (56+33) within RTP::Webmerge::Optimize::BEGIN@13 which was called:
# once (56µs+33µs) by main::BEGIN@35 at line 13 # spent 90µs making 1 call to RTP::Webmerge::Optimize::BEGIN@13
# spent 33µs making 1 call to warnings::import |
| 14 | |||||
| 15 | ################################################################################################### | ||||
| 16 | |||||
| 17 | # global variables | ||||
| 18 | 1 | 2µs | our (%optimizer); | ||
| 19 | |||||
| 20 | ################################################################################################### | ||||
| 21 | |||||
| 22 | # define our version string | ||||
| 23 | 1 | 168µs | 1 | 24µs | # spent 24µs within RTP::Webmerge::Optimize::BEGIN@23 which was called:
# once (24µs+0s) by main::BEGIN@35 at line 23 # spent 24µs making 1 call to RTP::Webmerge::Optimize::BEGIN@23 |
| 24 | |||||
| 25 | # load exporter and inherit from it | ||||
| 26 | 3 | 374µs | 2 | 80µs | BEGIN { use Exporter qw(); our @ISA = qw(Exporter) } # spent 57µs making 1 call to RTP::Webmerge::Optimize::BEGIN@26.24
# spent 24µs making 1 call to RTP::Webmerge::Optimize::BEGIN@26 |
| 27 | |||||
| 28 | # define our functions to be exported | ||||
| 29 | 1 | 184µs | 1 | 30µs | # spent 30µs within RTP::Webmerge::Optimize::BEGIN@29 which was called:
# once (30µs+0s) by main::BEGIN@35 at line 29 # spent 30µs making 1 call to RTP::Webmerge::Optimize::BEGIN@29 |
| 30 | |||||
| 31 | # define our functions that can be exported | ||||
| 32 | 1 | 1.80ms | 1 | 29µs | # spent 29µs within RTP::Webmerge::Optimize::BEGIN@32 which was called:
# once (29µs+0s) by main::BEGIN@35 at line 32 # spent 29µs making 1 call to RTP::Webmerge::Optimize::BEGIN@32 |
| 33 | |||||
| 34 | ################################################################################################### | ||||
| 35 | |||||
| 36 | # main optimizer function | ||||
| 37 | # call all optimizer steps | ||||
| 38 | sub optimizer | ||||
| 39 | { | ||||
| 40 | |||||
| 41 | # get input variables | ||||
| 42 | my ($config, $optimize) = @_; | ||||
| 43 | |||||
| 44 | # do nothing if level is zero | ||||
| 45 | return unless $config->{'level'}; | ||||
| 46 | |||||
| 47 | # check for configuration option | ||||
| 48 | return unless $config->{'optimize'}; | ||||
| 49 | |||||
| 50 | # should we commit filesystem changes? | ||||
| 51 | my $commit = $optimize->{'commit'} || 0; | ||||
| 52 | |||||
| 53 | # commit all changes to the filesystem if configured | ||||
| 54 | $config->{'atomic'} = {} if $commit =~ m/^\s*(?:bo|be)/i; | ||||
| 55 | |||||
| 56 | # do not process if disabled attribute is given and set to true | ||||
| 57 | unless ($optimize->{'disabled'} && lc $optimize->{'disabled'} eq 'true') | ||||
| 58 | { | ||||
| 59 | |||||
| 60 | # change directory (restore previous state after this block) | ||||
| 61 | my $dir = RTP::Webmerge::Path->chdir($optimize->{'chdir'}); | ||||
| 62 | |||||
| 63 | # process all optimizers | ||||
| 64 | foreach my $key (sort keys %optimizer) | ||||
| 65 | { | ||||
| 66 | # check if this optimizer is enabled | ||||
| 67 | next unless $config->{'optimize-' . $key}; | ||||
| 68 | # call the optimizer functions (see modules) | ||||
| 69 | $optimizer{$key}->($config, $optimize->{$key} || []); | ||||
| 70 | } | ||||
| 71 | |||||
| 72 | } | ||||
| 73 | # EO unless disabled | ||||
| 74 | |||||
| 75 | # commit all changes to the filesystem if configured | ||||
| 76 | $config->{'atomic'} = {} if $commit =~ m/^\s*(?:bo|af)/i; | ||||
| 77 | |||||
| 78 | } | ||||
| 79 | # EO sub optimize | ||||
| 80 | |||||
| 81 | ################################################################################################### | ||||
| 82 | |||||
| 83 | # load function from main module | ||||
| 84 | 2 | 318µs | 2 | 689µs | # spent 401µs (113+288) within RTP::Webmerge::Optimize::BEGIN@84 which was called:
# once (113µs+288µs) by main::BEGIN@35 at line 84 # spent 401µs making 1 call to RTP::Webmerge::Optimize::BEGIN@84
# spent 288µs making 1 call to Exporter::import |
| 85 | |||||
| 86 | # load functions from webmerge io library | ||||
| 87 | 2 | 276µs | 2 | 554µs | # spent 323µs (92+231) within RTP::Webmerge::Optimize::BEGIN@87 which was called:
# once (92µs+231µs) by main::BEGIN@35 at line 87 # spent 323µs making 1 call to RTP::Webmerge::Optimize::BEGIN@87
# spent 231µs making 1 call to Exporter::import |
| 88 | |||||
| 89 | # load function from main module | ||||
| 90 | 2 | 1.90ms | 2 | 540µs | # spent 312µs (83+228) within RTP::Webmerge::Optimize::BEGIN@90 which was called:
# once (83µs+228µs) by main::BEGIN@35 at line 90 # spent 312µs making 1 call to RTP::Webmerge::Optimize::BEGIN@90
# spent 228µs making 1 call to Exporter::import |
| 91 | |||||
| 92 | ################################################################################################### | ||||
| 93 | |||||
| 94 | # create a new sub to optimize files | ||||
| 95 | # pass the filetype to be optimized | ||||
| 96 | sub optimize ($) | ||||
| 97 | # spent 278µs within RTP::Webmerge::Optimize::optimize which was called 7 times, avg 40µs/call:
# once (62µs+0s) by main::BEGIN@49 at line 86 of webmerge/scripts/modules/RTP/Webmerge/Optimize/PNG.pm
# once (38µs+0s) by main::BEGIN@47 at line 78 of webmerge/scripts/modules/RTP/Webmerge/Optimize/GIF.pm
# once (37µs+0s) by main::BEGIN@46 at line 138 of webmerge/scripts/modules/RTP/Webmerge/Optimize/TXT.pm
# once (35µs+0s) by main::BEGIN@52 at line 78 of webmerge/scripts/modules/RTP/Webmerge/Optimize/GZ.pm
# once (35µs+0s) by main::BEGIN@48 at line 77 of webmerge/scripts/modules/RTP/Webmerge/Optimize/JPG.pm
# once (35µs+0s) by main::BEGIN@51 at line 78 of webmerge/scripts/modules/RTP/Webmerge/Optimize/ZIP.pm
# once (35µs+0s) by main::BEGIN@50 at line 83 of webmerge/scripts/modules/RTP/Webmerge/Optimize/MNG.pm | ||||
| 98 | |||||
| 99 | # create a closure variable | ||||
| 100 | 7 | 46µs | my ($filetype) = @_; | ||
| 101 | |||||
| 102 | # create new subroutine | ||||
| 103 | return sub | ||||
| 104 | { | ||||
| 105 | |||||
| 106 | # get input variables | ||||
| 107 | my ($config, $entries) = @_; | ||||
| 108 | |||||
| 109 | # process all entries | ||||
| 110 | foreach my $nodes (@{$entries}) | ||||
| 111 | { | ||||
| 112 | |||||
| 113 | # declare lexical variables | ||||
| 114 | my $disabled = $nodes->{'disabled'}; | ||||
| 115 | |||||
| 116 | # do not process if entry has been disabled | ||||
| 117 | return if $disabled && lc $disabled eq 'true'; | ||||
| 118 | |||||
| 119 | # process all file entries | ||||
| 120 | foreach my $entry (@{$nodes->{'file'} || []}) | ||||
| 121 | { | ||||
| 122 | |||||
| 123 | # declare lexical variables | ||||
| 124 | my $file = $entry->{'file'}; | ||||
| 125 | my $path = $entry->{'path'} || '.'; | ||||
| 126 | my $disabled = $entry->{'disabled'} || 'false'; | ||||
| 127 | my $recursive = $entry->{'recursive'} || 'false'; | ||||
| 128 | |||||
| 129 | # do not process if entry has been disabled | ||||
| 130 | return if $disabled && lc $disabled eq 'true'; | ||||
| 131 | |||||
| 132 | # create pattern for logging | ||||
| 133 | my $pattern = join('/', $path, $file); | ||||
| 134 | |||||
| 135 | # make sure we pass a boolean value | ||||
| 136 | $recursive = 0 if $recursive eq 'false'; | ||||
| 137 | |||||
| 138 | # get all files for the resolved path and pattern | ||||
| 139 | my $files = filelist(check_path($path), $file, $recursive); | ||||
| 140 | |||||
| 141 | # call all possible optimizers | ||||
| 142 | callProgram($config, $filetype . 'opt', $files, $pattern, $entry); | ||||
| 143 | |||||
| 144 | } | ||||
| 145 | # EO each file entry | ||||
| 146 | |||||
| 147 | } | ||||
| 148 | # EO each nodes | ||||
| 149 | |||||
| 150 | 7 | 422µs | }; | ||
| 151 | # EO sub optimizer | ||||
| 152 | |||||
| 153 | } | ||||
| 154 | # EO sub optimize | ||||
| 155 | |||||
| 156 | ################################################################################################### | ||||
| 157 | ################################################################################################### | ||||
| 158 | 1 | 20µs | 1; |