line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MicroMason::Safe; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
889
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
4
|
2
|
|
|
2
|
|
5
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
80
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
407
|
use Safe; |
|
2
|
|
|
|
|
22995
|
|
|
2
|
|
|
|
|
712
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
###################################################################### |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub eval_sub { |
11
|
2
|
|
|
2
|
1
|
3
|
my ( $self, $code ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
|
|
6
|
my $safe = $self->safe_compartment(); |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
1231
|
local $Text::MicroMason::Commands::m = $self->safe_facade(); |
16
|
2
|
|
|
|
|
4
|
$safe->share_from( 'Text::MicroMason::Commands' => [ '$m' ] ); |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
68
|
$safe->reval( "my \$m = \$m; $code", 1 ) |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# $self_or_safe = $mason->safe_compartment(); |
22
|
|
|
|
|
|
|
sub safe_compartment { |
23
|
2
|
|
|
2
|
1
|
2
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
2
|
50
|
33
|
|
|
6
|
if ( ! $self->{safe} or $self->{safe} eq '1' ) { |
|
|
0
|
|
|
|
|
|
26
|
2
|
|
|
|
|
7
|
return Safe->new() |
27
|
|
|
|
|
|
|
} elsif ( UNIVERSAL::can( $self->{safe}, 'reval' ) ) { |
28
|
|
|
|
|
|
|
return $self->{safe} |
29
|
0
|
|
|
|
|
0
|
} else { |
30
|
0
|
|
|
|
|
0
|
$self->croak_msg("Inappropriate Safe compartment:", $self->{safe}); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub safe_facade { |
35
|
2
|
|
|
2
|
1
|
2
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
4
|
our @CARP_NOT = qw(Text::MicroMason::Base); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
carp("* WARNING: safe_methods is deprecated; please see the pod") |
40
|
2
|
50
|
|
|
|
4
|
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
|
2
|
0
|
|
|
|
10
|
map { ! $_ ? () : ref($_) ? @$_ : split ' ' } $self->{safe_methods} |
|
|
50
|
|
|
|
|
|
48
|
|
|
|
|
|
|
) |
49
|
2
|
|
|
|
|
3
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
###################################################################### |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Text::MicroMason::Safe::Facade; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
2
|
|
|
2
|
|
2
|
my $class = shift; |
57
|
2
|
|
|
|
|
4
|
bless { @_ }, $class |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub facade_method { |
61
|
0
|
|
|
0
|
|
|
my ( $self, $method, @args ) = @_; |
62
|
0
|
0
|
|
|
|
|
my $sub = $self->{$method} |
63
|
|
|
|
|
|
|
or die "Can't call \$m->$method() in this compartment"; |
64
|
0
|
|
|
|
|
|
&$sub( @args ) |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub AUTOLOAD { |
68
|
0
|
|
|
0
|
|
|
my $sym = $Text::MicroMason::Safe::Facade::AUTOLOAD; |
69
|
0
|
|
|
|
|
|
my ($package, $func) = ($sym =~ /(.*)::([^:]+)$/); |
70
|
0
|
0
|
|
|
|
|
return unless ( $func =~ /^[a-z\_]+$/ ); |
71
|
2
|
|
|
2
|
|
8
|
no strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
112
|
|
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__ |