line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MicroMason::Safe; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1047
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
103
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
434
|
use Safe; |
|
2
|
|
|
|
|
30427
|
|
|
2
|
|
|
|
|
1077
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
###################################################################### |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub eval_sub { |
11
|
20
|
|
|
20
|
1
|
96
|
my ( $self, $code ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
20
|
|
|
|
|
75
|
my $safe = $self->safe_compartment(); |
14
|
|
|
|
|
|
|
|
15
|
20
|
|
|
|
|
12047
|
local $Text::MicroMason::Commands::m = $self->safe_facade(); |
16
|
20
|
|
|
|
|
76
|
$safe->share_from( 'Text::MicroMason::Commands' => [ '$m' ] ); |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
844
|
$safe->reval( "my \$m = \$m; $code", 1 ) |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# $self_or_safe = $mason->safe_compartment(); |
22
|
|
|
|
|
|
|
sub safe_compartment { |
23
|
20
|
|
|
20
|
1
|
27
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
20
|
100
|
66
|
|
|
95
|
if ( ! $self->{safe} or $self->{safe} eq '1' ) { |
|
|
50
|
|
|
|
|
|
26
|
12
|
|
|
|
|
57
|
return Safe->new() |
27
|
|
|
|
|
|
|
} elsif ( UNIVERSAL::can( $self->{safe}, 'reval' ) ) { |
28
|
|
|
|
|
|
|
return $self->{safe} |
29
|
8
|
|
|
|
|
22
|
} else { |
30
|
0
|
|
|
|
|
0
|
$self->croak_msg("Inappropriate Safe compartment:", $self->{safe}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub safe_facade { |
35
|
20
|
|
|
20
|
1
|
31
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
20
|
|
|
|
|
44
|
our @CARP_NOT = qw(Text::MicroMason::Base); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
carp("* WARNING: safe_methods is deprecated; please see the pod") |
40
|
20
|
50
|
|
|
|
47
|
if $self->{safe_methods}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Text::MicroMason::Safe::Facade->new( |
43
|
|
|
|
|
|
|
map { |
44
|
0
|
|
|
|
|
0
|
my $method = $_; |
45
|
0
|
|
|
0
|
|
0
|
$_ => sub { $self->$method( @_ ) } |
46
|
0
|
|
|
|
|
0
|
} |
47
|
20
|
0
|
|
|
|
110
|
map { ! $_ ? () : ref($_) ? @$_ : split ' ' } $self->{safe_methods} |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
) |
49
|
20
|
|
|
|
|
50
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
###################################################################### |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Text::MicroMason::Safe::Facade; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
20
|
|
|
20
|
|
28
|
my $class = shift; |
57
|
20
|
|
|
|
|
81
|
bless { @_ }, $class |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub facade_method { |
61
|
0
|
|
|
0
|
|
0
|
my ( $self, $method, @args ) = @_; |
62
|
0
|
0
|
|
|
|
0
|
my $sub = $self->{$method} |
63
|
|
|
|
|
|
|
or die "Can't call \$m->$method() in this compartment"; |
64
|
0
|
|
|
|
|
0
|
&$sub( @args ) |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub AUTOLOAD { |
68
|
20
|
|
|
20
|
|
11228
|
my $sym = $Text::MicroMason::Safe::Facade::AUTOLOAD; |
69
|
20
|
|
|
|
|
104
|
my ($package, $func) = ($sym =~ /(.*)::([^:]+)$/); |
70
|
20
|
50
|
|
|
|
419
|
return unless ( $func =~ /^[a-z\_]+$/ ); |
71
|
2
|
|
|
2
|
|
19
|
no strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
171
|
|
72
|
0
|
|
|
0
|
|
|
my $sub = *{$func} = sub { (shift)->facade_method($func, @_ ) }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
goto &$sub; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
###################################################################### |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |