Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Optimize/TXT.pm |
Statements | Executed 29 statements in 4.06ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 92µs | 361µs | BEGIN@8 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 62µs | 745µs | BEGIN@72 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 61µs | 94µs | BEGIN@10 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 60µs | 220µs | BEGIN@75 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 55µs | 55µs | BEGIN@18.32 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 52µs | 139µs | BEGIN@9 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 42µs | 42µs | __ANON__[:132] | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 37µs | 37µs | __ANON__[:108] | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 31µs | 31µs | BEGIN@21 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 24µs | 24µs | BEGIN@18 | RTP::Webmerge::Optimize::TXT::
1 | 1 | 1 | 23µs | 23µs | BEGIN@15 | RTP::Webmerge::Optimize::TXT::
0 | 0 | 0 | 0s | 0s | __ANON__[:130] | RTP::Webmerge::Optimize::TXT::
0 | 0 | 0 | 0s | 0s | cleantxt | RTP::Webmerge::Optimize::TXT::
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::Optimize::TXT; | ||||
6 | ################################################################################################### | ||||
7 | |||||
8 | 2 | 164µs | 2 | 630µs | # spent 361µs (92+269) within RTP::Webmerge::Optimize::TXT::BEGIN@8 which was called:
# once (92µs+269µs) by main::BEGIN@46 at line 8 # spent 361µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@8
# spent 269µs making 1 call to Exporter::import |
9 | 2 | 151µs | 2 | 225µs | # spent 139µs (52+86) within RTP::Webmerge::Optimize::TXT::BEGIN@9 which was called:
# once (52µs+86µs) by main::BEGIN@46 at line 9 # spent 139µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@9
# spent 86µs making 1 call to strict::import |
10 | 2 | 200µs | 2 | 127µs | # spent 94µs (61+33) within RTP::Webmerge::Optimize::TXT::BEGIN@10 which was called:
# once (61µs+33µs) by main::BEGIN@46 at line 10 # spent 94µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@10
# spent 33µs making 1 call to warnings::import |
11 | |||||
12 | ################################################################################################### | ||||
13 | |||||
14 | # define our version string | ||||
15 | 1 | 159µs | 1 | 23µs | # spent 23µs within RTP::Webmerge::Optimize::TXT::BEGIN@15 which was called:
# once (23µs+0s) by main::BEGIN@46 at line 15 # spent 23µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@15 |
16 | |||||
17 | # load exporter and inherit from it | ||||
18 | 3 | 447µs | 2 | 79µs | BEGIN { use Exporter qw(); our @ISA = qw(Exporter) } # spent 55µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@18.32
# spent 24µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@18 |
19 | |||||
20 | # define our functions to be exported | ||||
21 | 1 | 1.26ms | 1 | 31µs | # spent 31µs within RTP::Webmerge::Optimize::TXT::BEGIN@21 which was called:
# once (31µs+0s) by main::BEGIN@46 at line 21 # spent 31µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@21 |
22 | |||||
23 | ################################################################################################### | ||||
24 | |||||
25 | # safe text cleaning | ||||
26 | # for html, css and js | ||||
27 | # changes source files | ||||
28 | sub cleantxt ($$;$) | ||||
29 | { | ||||
30 | |||||
31 | # get input variables | ||||
32 | my ($data, $config, $options) = @_; | ||||
33 | |||||
34 | # options are really optional | ||||
35 | $options = {} unless $options; | ||||
36 | |||||
37 | # defined end of line characters | ||||
38 | # only auto switch between win and linux | ||||
39 | my $eol = $^O eq "MSWin32" ? "\r\n" : "\n"; | ||||
40 | |||||
41 | # get the end of line type | ||||
42 | my $type = $options->{'type'} | ||||
43 | || $config->{'txt-type'} | ||||
44 | || 'auto'; | ||||
45 | |||||
46 | # check for other forced types | ||||
47 | $eol = "\r\n" if $type =~ m/w/i; # win | ||||
48 | $eol = "\r" if $type =~ m/c/i; # mac | ||||
49 | $eol = "\n" if $type =~ m/x/i; # nix | ||||
50 | |||||
51 | # remove unwanted utf8 boms | ||||
52 | if ($config->{'txt-remove-bom'}) | ||||
53 | { ${$data} =~ s/^\xEF\xBB\xBF//; } | ||||
54 | |||||
55 | # trim trailing whitespace | ||||
56 | if ($config->{'txt-trim-trailing'}) | ||||
57 | { ${$data} =~ s/[ \f\t]+(?=[\n\r])//gm; } | ||||
58 | |||||
59 | # convert newlines to desired type | ||||
60 | if ($config->{'txt-normalize-eol'}) | ||||
61 | { ${$data} =~ s/(?:\r\n|\n\r|\n|\r)/$eol/gm; } | ||||
62 | |||||
63 | # return success | ||||
64 | return 1; | ||||
65 | |||||
66 | } | ||||
67 | # EO sub cleantxt | ||||
68 | |||||
69 | ################################################################################################### | ||||
70 | |||||
71 | # load webmberge module variables to hook | ||||
72 | 2 | 217µs | 2 | 1.43ms | # spent 745µs (62+683) within RTP::Webmerge::Optimize::TXT::BEGIN@72 which was called:
# once (62µs+683µs) by main::BEGIN@46 at line 72 # spent 745µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@72
# spent 683µs making 1 call to Exporter::import |
73 | |||||
74 | # load functions from webmerge io library | ||||
75 | 2 | 1.28ms | 2 | 380µs | # spent 220µs (60+160) within RTP::Webmerge::Optimize::TXT::BEGIN@75 which was called:
# once (60µs+160µs) by main::BEGIN@46 at line 75 # spent 220µs making 1 call to RTP::Webmerge::Optimize::TXT::BEGIN@75
# spent 160µs making 1 call to Exporter::import |
76 | |||||
77 | ################################################################################################### | ||||
78 | |||||
79 | # push to initers | ||||
80 | # return for getOpts | ||||
81 | push @initers, sub | ||||
82 | # spent 37µs within RTP::Webmerge::Optimize::TXT::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Optimize/TXT.pm:108] which was called:
# once (37µs+0s) by RTP::Webmerge::initConfig at line 263 of webmerge/scripts/modules/RTP/Webmerge.pm | ||||
83 | |||||
84 | # get config | ||||
85 | 1 | 4µs | my ($config) = @_; | ||
86 | |||||
87 | # create config variable to be available | ||||
88 | 1 | 4µs | $config->{'cmd_optimize-txt'} = 1; | ||
89 | |||||
90 | # text file type [nix|mac|win] | ||||
91 | 1 | 2µs | $config->{'cmd_txt-type'} = 1; | ||
92 | # remove superfluous utf boms | ||||
93 | 1 | 2µs | $config->{'cmd_txt-remove-bom'} = 1; | ||
94 | # normalize line endings to given type | ||||
95 | 1 | 2µs | $config->{'cmd_txt-normalize-eol'} = 1; | ||
96 | # trim trailing whitespace in text files | ||||
97 | 1 | 3µs | $config->{'cmd_txt-trim-trailing'} = 1; | ||
98 | |||||
99 | # connect each tmpl variable with the getOpt option | ||||
100 | return ( | ||||
101 | 1 | 36µs | 'optimize-txt|txt!', \ $config->{'cmd_optimize-txt'}, | ||
102 | 'txt-type=s', \ $config->{'cmd_txt-type'}, | ||||
103 | 'txt-remove-bom!', \ $config->{'cmd_txt-remove-bom'}, | ||||
104 | 'txt-normalize-eol!', \ $config->{'cmd_txt-normalize-eol'}, | ||||
105 | 'txt-trim-trailing!', \ $config->{'cmd_txt-trim-trailing'}, | ||||
106 | ); | ||||
107 | |||||
108 | 1 | 16µs | }; | ||
109 | # EO push initer | ||||
110 | |||||
111 | ################################################################################################### | ||||
112 | |||||
113 | # push to checkers | ||||
114 | push @checkers, sub | ||||
115 | # spent 42µs within RTP::Webmerge::Optimize::TXT::__ANON__[/home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Optimize/TXT.pm:132] which was called:
# once (42µs+0s) by RTP::Webmerge::checkConfig at line 290 of webmerge/scripts/modules/RTP/Webmerge.pm | ||||
116 | |||||
117 | # get config | ||||
118 | 1 | 3µs | my ($config) = @_; | ||
119 | |||||
120 | # disable if not optimizing | ||||
121 | 1 | 5µs | unless ($config->{'optimize'}) | ||
122 | { $config->{'optimize-txt'} = 0; } | ||||
123 | |||||
124 | # define executables to optimize txts | ||||
125 | $executables{'txtopt'} = ['txtopt', sub { | ||||
126 | |||||
127 | # process that file via cleantxt (pass options) | ||||
128 | return processfile($_[0], \&cleantxt, $_[1], $_[2]); | ||||
129 | |||||
130 | 1 | 48µs | }, 1]; | ||
131 | |||||
132 | 1 | 16µs | }; | ||
133 | # EO push checker | ||||
134 | |||||
135 | ################################################################################################### | ||||
136 | |||||
137 | # now create a new file optimizer subroutine and hook it our optimizers | ||||
138 | 1 | 21µs | 1 | 37µs | $RTP::Webmerge::Optimize::optimizer{'txt'} = RTP::Webmerge::Optimize::optimize('txt'); # spent 37µs making 1 call to RTP::Webmerge::Optimize::optimize |
139 | |||||
140 | ################################################################################################### | ||||
141 | ################################################################################################### | ||||
142 | 1 | 24µs | 1; |