line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MicroMason::Safe; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1091
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
382
|
use Safe; |
|
2
|
|
|
|
|
26960
|
|
|
2
|
|
|
|
|
952
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
###################################################################### |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub eval_sub { |
11
|
20
|
|
|
20
|
1
|
81
|
my ( $self, $code ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
20
|
|
|
|
|
55
|
my $safe = $self->safe_compartment(); |
14
|
|
|
|
|
|
|
|
15
|
20
|
|
|
|
|
9201
|
local $Text::MicroMason::Commands::m = $self->safe_facade(); |
16
|
20
|
|
|
|
|
61
|
$safe->share_from( 'Text::MicroMason::Commands' => [ '$m' ] ); |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
734
|
$safe->reval( "my \$m = \$m; $code", 1 ) |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# $self_or_safe = $mason->safe_compartment(); |
22
|
|
|
|
|
|
|
sub safe_compartment { |
23
|
20
|
|
|
20
|
1
|
28
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
20
|
100
|
66
|
|
|
82
|
if ( ! $self->{safe} or $self->{safe} eq '1' ) { |
|
|
50
|
|
|
|
|
|
26
|
12
|
|
|
|
|
61
|
return Safe->new() |
27
|
|
|
|
|
|
|
} elsif ( UNIVERSAL::can( $self->{safe}, 'reval' ) ) { |
28
|
|
|
|
|
|
|
return $self->{safe} |
29
|
8
|
|
|
|
|
21
|
} else { |
30
|
0
|
|
|
|
|
0
|
$self->croak_msg("Inappropriate Safe compartment:", $self->{safe}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub safe_facade { |
35
|
20
|
|
|
20
|
1
|
27
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
20
|
|
|
|
|
35
|
our @CARP_NOT = qw(Text::MicroMason::Base); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
carp("* WARNING: safe_methods is deprecated; please see the pod") |
40
|
20
|
50
|
|
|
|
44
|
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
|
|
|
|
86
|
map { ! $_ ? () : ref($_) ? @$_ : split ' ' } $self->{safe_methods} |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
) |
49
|
20
|
|
|
|
|
35
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
###################################################################### |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Text::MicroMason::Safe::Facade; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
20
|
|
|
20
|
|
35
|
my $class = shift; |
57
|
20
|
|
|
|
|
46
|
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
|
|
9518
|
my $sym = $Text::MicroMason::Safe::Facade::AUTOLOAD; |
69
|
20
|
|
|
|
|
95
|
my ($package, $func) = ($sym =~ /(.*)::([^:]+)$/); |
70
|
20
|
50
|
|
|
|
217
|
return unless ( $func =~ /^[a-z\_]+$/ ); |
71
|
2
|
|
|
2
|
|
15
|
no strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
158
|
|
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__ |