| 1 | package Zuzu::Module::Eval; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 3 | our $VERSION = '0.007002'; | |||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use Zuzu::Error; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use Zuzu::Util::NativeHelpers qw( native_function zuzu_bool ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 12 | ▶ | sub IMPORT { | ||||||||||
|
Subroutine
IMPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 11 | 12 | my ( $class, $runtime ) = @_; | |||||||||||
| 12 | |||||||||||||
| 13 | my $eval_fn = native_function( | ||||||||||||
| 14 | name => 'eval', | ||||||||||||
| 15 | accepts_named => 1, | ||||||||||||
| 16 | 24 | ▶ | native => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=27.1
| |||||||||||||
| 17 | 24 | my ( $source, $named ) = @_; | |||||||||||
| 18 | 24 | my $type = $runtime->_type_name( $source ); | |||||||||||
| 19 | 24 | ▶ | if ( $type ne 'String' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 0 | die Zuzu::Error->new_runtime( | |||||||||||
| 21 | message => "TypeException: eval expects String, got $type", | ||||||||||||
| 22 | file => '<std/eval>', | ||||||||||||
| 23 | line => 0, | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 24 | ▶ | $named //= {}; | ||||||||||
|
Condition100%2/2
$named //= {}
MC/DC100%1/1
$named //= {}
$named
Truth table100%2/2
A
A= $named
| |||||||||||||
| 28 | 24 | my %allowed = map { $_ => 1 } qw( | |||||||||||
| 29 | deny_fs | ||||||||||||
| 30 | deny_net | ||||||||||||
| 31 | deny_perl | ||||||||||||
| 32 | deny_js | ||||||||||||
| 33 | deny_proc | ||||||||||||
| 34 | deny_db | ||||||||||||
| 35 | deny_clib | ||||||||||||
| 36 | deny_gui | ||||||||||||
| 37 | deny_worker | ||||||||||||
| 38 | ); | ||||||||||||
| 39 | 24 | for my $key ( CORE::keys %{$named} ) { | |||||||||||
| 40 | 8 | ▶ | next if $allowed{$key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 1 | die Zuzu::Error->new_runtime( | |||||||||||
| 42 | message => "Unknown named argument '$key' for eval", | ||||||||||||
| 43 | file => '<std/eval>', | ||||||||||||
| 44 | line => 0, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 23 | my @extra_denials; | |||||||||||
| 49 | 23 | ▶ | push @extra_denials, 'fs' if zuzu_bool( $named->{deny_fs}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 23 | ▶ | push @extra_denials, 'net' if zuzu_bool( $named->{deny_net}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 23 | ▶ | push @extra_denials, 'perl' if zuzu_bool( $named->{deny_perl}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 23 | ▶ | push @extra_denials, 'js' if zuzu_bool( $named->{deny_js}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 23 | ▶ | push @extra_denials, 'proc' if zuzu_bool( $named->{deny_proc}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 23 | ▶ | push @extra_denials, 'db' if zuzu_bool( $named->{deny_db}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | 23 | ▶ | push @extra_denials, 'clib' if zuzu_bool( $named->{deny_clib}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 23 | ▶ | push @extra_denials, 'gui' if zuzu_bool( $named->{deny_gui}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 23 | ▶ | push @extra_denials, 'worker' if zuzu_bool( $named->{deny_worker}, 0 ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | |||||||||||||
| 59 | 23 | return $runtime->eval_with_current_scope_denials( | |||||||||||
| 60 | $source, | ||||||||||||
| 61 | '<std/eval>', | ||||||||||||
| 62 | \@extra_denials, | ||||||||||||
| 63 | ); | ||||||||||||
| 64 | }, | ||||||||||||
| 65 | 12 | ); | |||||||||||
| 66 | |||||||||||||
| 67 | return { | ||||||||||||
| 68 | 12 | eval => $eval_fn, | |||||||||||
| 69 | }; | ||||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 3 | 1; | |||||||||||
| 73 | |||||||||||||
| 74 | =pod | ||||||||||||
| 75 | |||||||||||||
| 76 | =head1 COPYRIGHT AND LICENCE | ||||||||||||
| 77 | |||||||||||||
| 78 | B<< Zuzu::Module::Eval >> is copyright Toby Inkster. | ||||||||||||
| 79 | |||||||||||||
| 80 | It is free software; you may redistribute it and/or modify it under | ||||||||||||
| 81 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||
| 82 | License version 2. | ||||||||||||
| 83 | |||||||||||||
| 84 | =cut | ||||||||||||