line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# PerlCode; allow arbitrary perl code be embedded in a WebMake file. |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::WebMake::PerlCode; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
122
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use HTML::WebMake::Main; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
9
|
1
|
|
|
1
|
|
1198
|
use HTML::WebMake::PerlCodeLibrary; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
38
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
695
|
use vars qw{ |
12
|
|
|
|
|
|
|
@ISA $CAN_USE_IO_STRING |
13
|
|
|
|
|
|
|
$GlobalSelf @PrevSelves %SORT_SUBS |
14
|
1
|
|
|
1
|
|
10
|
}; |
|
1
|
|
|
|
|
2
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@ISA = qw(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
########################################################################### |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new ($$) { |
21
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
22
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
23
|
0
|
|
|
|
|
|
my ($main) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $self = { |
26
|
|
|
|
|
|
|
'main' => $main, |
27
|
|
|
|
|
|
|
}; |
28
|
0
|
|
|
|
|
|
bless ($self, $class); |
29
|
0
|
|
|
|
|
|
$self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub can_use_io_string { |
33
|
0
|
0
|
|
0
|
0
|
|
if (defined $CAN_USE_IO_STRING) { return $CAN_USE_IO_STRING; } |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$CAN_USE_IO_STRING = 0; |
36
|
0
|
|
|
|
|
|
eval q{ |
37
|
|
|
|
|
|
|
require IO::String; $CAN_USE_IO_STRING = 1; 1; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $CAN_USE_IO_STRING; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new_io_string { |
44
|
0
|
|
|
0
|
0
|
|
eval q{ |
45
|
|
|
|
|
|
|
return new IO::String (); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
0
|
|
sub dbg { HTML::WebMake::Main::dbg (@_); } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub interpret { |
54
|
0
|
|
|
0
|
0
|
|
my ($self, $type, $str, $defunderscoreval) = @_; |
55
|
0
|
|
|
|
|
|
my ($ret); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
local ($_) = $defunderscoreval; |
58
|
0
|
0
|
|
|
|
|
if (!defined ($_)) { $_ = ''; } |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ($self->{main}->{paranoid}) { |
61
|
0
|
|
|
|
|
|
return "\n(Paranoid mode on - perl code evaluation prohibited.)\n"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# note that both $self and $_ are available from within evaluated |
65
|
|
|
|
|
|
|
# perl code. |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->enter_perl_call(); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
if ($type ne "perlout") { |
70
|
0
|
|
|
|
|
|
$ret = eval 'package main; '.$str; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} else { |
73
|
0
|
0
|
|
|
|
|
if (!can_use_io_string()) { |
74
|
0
|
|
|
|
|
|
warn "<{perlout}> code failed: IO::String module not available\n"; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
|
my $outhandle = new_io_string(); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$ret = eval 'package main; select $outhandle; '.$str; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if (defined($ret)) { |
82
|
0
|
|
|
|
|
|
$ret = ${$outhandle->string_ref()}; |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
chomp $ret; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
select STDOUT; |
87
|
0
|
|
|
|
|
|
$outhandle = undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->exit_perl_call(); |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if (!defined $ret) { |
94
|
0
|
|
|
|
|
|
warn "<{perl}> code failed: $@\nCode: $str\n"; |
95
|
0
|
|
|
|
|
|
$ret = ''; |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
$ret; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub enter_perl_call { |
101
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
102
|
0
|
|
|
|
|
|
push (@PrevSelves, $GlobalSelf); $GlobalSelf = $self; |
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub exit_perl_call { |
106
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
107
|
0
|
|
|
|
|
|
$GlobalSelf = pop (@PrevSelves); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# get and eval() a sort subroutine for the given sorting criteria. |
113
|
|
|
|
|
|
|
# stores cached sort sub { } refs in the %SORT_SUBS global array to |
114
|
|
|
|
|
|
|
# avoid re-evaluating the same piece of perl code repeatedly. |
115
|
|
|
|
|
|
|
# |
116
|
|
|
|
|
|
|
sub get_sort_sub { |
117
|
0
|
|
|
0
|
0
|
|
my ($self, $sortstr) = @_; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if (!defined $SORT_SUBS{$sortstr}) { |
120
|
0
|
|
|
|
|
|
my $sortsubstr = $self->{main}->{metadata}->string_to_sort_sub ($sortstr); |
121
|
0
|
|
|
|
|
|
my $sortsub = eval $sortsubstr; |
122
|
0
|
|
|
|
|
|
$SORT_SUBS{$sortstr} = $sortsub; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$SORT_SUBS{$sortstr}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |