| Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/RTP/Webmerge/Compile/JS.pm |
| Statements | Executed 16 statements in 3.23ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 14.9ms | 138ms | RTP::Webmerge::Compile::JS::BEGIN@26 |
| 1 | 1 | 1 | 89µs | 401µs | RTP::Webmerge::Compile::JS::BEGIN@8 |
| 1 | 1 | 1 | 63µs | 658µs | RTP::Webmerge::Compile::JS::BEGIN@29 |
| 1 | 1 | 1 | 55µs | 89µs | RTP::Webmerge::Compile::JS::BEGIN@10 |
| 1 | 1 | 1 | 54µs | 54µs | RTP::Webmerge::Compile::JS::BEGIN@18.27 |
| 1 | 1 | 1 | 53µs | 141µs | RTP::Webmerge::Compile::JS::BEGIN@9 |
| 1 | 1 | 1 | 29µs | 29µs | RTP::Webmerge::Compile::JS::BEGIN@21 |
| 1 | 1 | 1 | 24µs | 24µs | RTP::Webmerge::Compile::JS::BEGIN@18 |
| 1 | 1 | 1 | 24µs | 24µs | RTP::Webmerge::Compile::JS::BEGIN@15 |
| 0 | 0 | 0 | 0s | 0s | RTP::Webmerge::Compile::JS::compileJS |
| 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::Compile::JS; | ||||
| 6 | ################################################################################################### | ||||
| 7 | |||||
| 8 | 2 | 168µs | 2 | 713µs | # spent 401µs (89+312) within RTP::Webmerge::Compile::JS::BEGIN@8 which was called:
# once (89µs+312µs) by main::BEGIN@40 at line 8 # spent 401µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@8
# spent 312µs making 1 call to Exporter::import |
| 9 | 2 | 172µs | 2 | 229µs | # spent 141µs (53+88) within RTP::Webmerge::Compile::JS::BEGIN@9 which was called:
# once (53µs+88µs) by main::BEGIN@40 at line 9 # spent 141µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@9
# spent 88µs making 1 call to strict::import |
| 10 | 2 | 200µs | 2 | 123µs | # spent 89µs (55+34) within RTP::Webmerge::Compile::JS::BEGIN@10 which was called:
# once (55µs+34µs) by main::BEGIN@40 at line 10 # spent 89µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@10
# spent 34µs making 1 call to warnings::import |
| 11 | |||||
| 12 | ################################################################################################### | ||||
| 13 | |||||
| 14 | # define our version string | ||||
| 15 | 1 | 154µs | 1 | 24µs | # spent 24µs within RTP::Webmerge::Compile::JS::BEGIN@15 which was called:
# once (24µs+0s) by main::BEGIN@40 at line 15 # spent 24µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@15 |
| 16 | |||||
| 17 | # load exporter and inherit from it | ||||
| 18 | 3 | 392µs | 2 | 78µs | BEGIN { use Exporter qw(); our @ISA = qw(Exporter) } # spent 54µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@18.27
# spent 24µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@18 |
| 19 | |||||
| 20 | # define our functions to be exported | ||||
| 21 | 1 | 164µs | 1 | 29µs | # spent 29µs within RTP::Webmerge::Compile::JS::BEGIN@21 which was called:
# once (29µs+0s) by main::BEGIN@40 at line 21 # spent 29µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@21 |
| 22 | |||||
| 23 | ################################################################################################### | ||||
| 24 | |||||
| 25 | # run3 to get stdout and stderr | ||||
| 26 | 2 | 730µs | 2 | 138ms | # spent 138ms (14.9+123) within RTP::Webmerge::Compile::JS::BEGIN@26 which was called:
# once (14.9ms+123ms) by main::BEGIN@40 at line 26 # spent 138ms making 1 call to RTP::Webmerge::Compile::JS::BEGIN@26
# spent 240µs making 1 call to Exporter::import |
| 27 | |||||
| 28 | # run3 to get stdout and stderr | ||||
| 29 | 2 | 1.24ms | 2 | 1.25ms | # spent 658µs (63+595) within RTP::Webmerge::Compile::JS::BEGIN@29 which was called:
# once (63µs+595µs) by main::BEGIN@40 at line 29 # spent 658µs making 1 call to RTP::Webmerge::Compile::JS::BEGIN@29
# spent 595µs making 1 call to Exporter::import |
| 30 | |||||
| 31 | ################################################################################################### | ||||
| 32 | |||||
| 33 | # compile js via google closure compiler | ||||
| 34 | #************************************************************************************************** | ||||
| 35 | sub compileJS | ||||
| 36 | { | ||||
| 37 | |||||
| 38 | # get input variables | ||||
| 39 | my ($content, $config) = @_; | ||||
| 40 | |||||
| 41 | # make these configurable again | ||||
| 42 | my $java_bin = '/usr/bin/java'; | ||||
| 43 | |||||
| 44 | # hotfix for windows operating system | ||||
| 45 | # all windows (even x64) report MSWin32! | ||||
| 46 | $java_bin = "java" if ($^O eq "MSWin32"); | ||||
| 47 | |||||
| 48 | # if java home is given we will force to use t | ||||
| 49 | if (exists $ENV{'JAVA_HOME'} && defined $ENV{'JAVA_HOME'}) | ||||
| 50 | { $java_bin = join(EOD, $ENV{'JAVA_HOME'}, 'bin', 'java'); } | ||||
| 51 | |||||
| 52 | # create the command to execute the closure compiler | ||||
| 53 | my $command = '"' . $java_bin . '" -jar ' . | ||||
| 54 | # reference the closure compiler relative from extension | ||||
| 55 | '"' . check_path('{EXT}/scripts/google/closure/compiler.jar') . '"' . | ||||
| 56 | # use quiet warning level and safe compilation options | ||||
| 57 | ' --warning_level QUIET --compilation_level SIMPLE_OPTIMIZATIONS'; | ||||
| 58 | |||||
| 59 | # I should only listen for my own children | ||||
| 60 | # IPC::Run3 will spawn it's own children | ||||
| 61 | local $SIG{CHLD} = undef; | ||||
| 62 | |||||
| 63 | # now call run3 to compile the javascript code | ||||
| 64 | my $rv = run3($command, \ $content, \ my $compiled, \ my $err); | ||||
| 65 | |||||
| 66 | # print content to console if we have errors | ||||
| 67 | # this should only ever print error messages | ||||
| 68 | print $compiled if $err || $? || $rv != 1; | ||||
| 69 | |||||
| 70 | # check if there was any error given by closure compiler | ||||
| 71 | die "closure compiler had an error, aborting\n$err", "\n" if $err; | ||||
| 72 | |||||
| 73 | # test if ipc run3 returned success | ||||
| 74 | die "closure compiler exited unexpectedly (code $?)", "\n" if $?; | ||||
| 75 | |||||
| 76 | # test if ipc run3 returned success | ||||
| 77 | die "could not run closure compiler, aborting", "\n" if $rv != 1; | ||||
| 78 | |||||
| 79 | # return compiled | ||||
| 80 | return $compiled; | ||||
| 81 | |||||
| 82 | } | ||||
| 83 | # EO sub compileJS | ||||
| 84 | |||||
| 85 | ################################################################################################### | ||||
| 86 | ################################################################################################### | ||||
| 87 | 1 | 14µs | 1; |