Treex/Block/Util/Find.pm

filter: Statementstmt 27.9% 12 / 43 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 2 / 4 Podpod 100% 1 / 1 totaltotal 20.0% 15 / 75 CC 15 SCAR 46.9
CC
15
Cov
18%
process_zone
156.0
_check_errors
20.0
BEGIN
1.0
CRAP 108.6
« Treex/Block/Util/FixInvalidIDs.pm ↑ Summary Treex/Core/Node/Ordered.pm »
1 package Treex::Block::Util::Find;
2 1 $Treex::Block::Util::Find::VERSION = '2.20210102';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'Treex::Block::Util::Eval';
6  
7 1 has on_error => (
8 is => 'ro',
9 isa => enum( [qw(fatal warn ignore)] ),
10 default => 'fatal',
11 documentation => 'what to do on errors in the code for eval',
12 );
13  
14 1 has expand_code => (
15 is=> 'ro',
16 isa => 'Bool',
17 default => 1,
18 documentation => 'Should "$." be expanded to "$this->" in all eval codes?',
19 );
20  
21 1 has max_nodes_per_tree => (
22 is=> 'ro',
23 isa => 'Int',
24 default => 0,
25 documentation => 'Print at most N trees for each tree. Default 0 means unlimited.',
26 );
27  
28  
29 ## no critic (ProhibitStringyEval) This block needs string evals
30 0 ▶sub process_zone {
Subroutine process_zone: not called CC=12 SCAR=50.5
Pod documented
31 0 my ( $self, $zone ) = @_;
32  
33 # Extract variables $bundle, $document ($doc), so they can be used in eval code
34 0 my $bundle = $zone->get_bundle();
35 0 my $document = $bundle->get_document();
36 0 my $doc = $document;
37  
38 0 foreach my $layer (qw(a t n p)) {
39 0 ▶ next if !$zone->has_tree($layer);
Branch: 1 branch
BranchTrueFalseTotal
unless $zone->has_tree($layer) 0 0 0
40 0 my $tree = $zone->get_tree($layer);
41 0 my $this = $tree;
42 0 ▶ if ( my $code = $self->_args->{"${layer}tree"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->_args->{"${layer}tree"}) 0 0 0
43 0 ▶ $code =~ s/\$\./\$this->/g if $self->expand_code;
Branch: 1 branch
BranchTrueFalseTotal
if $self->expand_code 0 0 0
44 0 ▶ if ( eval "my \$${layer}tree = \$tree; $code" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "my \$${layer}tree = \$tree; $code") 0 0 0
45 0 say $tree->get_address();
46 }
47 0 $self->_check_errors($code);
48 }
49 0 ▶ if ( my $code = $self->_args->{"${layer}node"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->_args->{"${layer}node"}) 0 0 0
50 0 my $nodes_found = 0;
51 0 ▶ $code =~ s/\$\./\$this->/g if $self->expand_code;
Branch: 1 branch
BranchTrueFalseTotal
if $self->expand_code 0 0 0
52 NODE:
53 0 foreach my $node ( $tree->get_descendants() ) {
54 0 $this = $node;
55 0 ▶ if ( eval "my \$${layer}node = \$node; $code" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "my \$${layer}node = \$node; $code") 0 0 0
56 0 say $node->get_address();
57 0 ▶ if ($self->max_nodes_per_tree){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->max_nodes_per_tree) 0 0 0
58 0 $nodes_found++;
59 0 ▶ last NODE if $nodes_found >= $self->max_nodes_per_tree;
Branch: 1 branch
BranchTrueFalseTotal
if $nodes_found >= $self->max_nodes_per_tree 0 0 0
60 }
61 }
62 0 $self->_check_errors($code);
63 }
64 }
65 }
66 0 return;
67 }
68  
69 0 ▶sub _check_errors {
Subroutine _check_errors: not called CC=4 SCAR=30.0
70 0 my ($self, $code) = @_;
71 0 ▶ return if !$@ || $self->on_error eq 'ignore';
Branch: 1 branch
BranchTrueFalseTotal
if not $@ or $self->on_error eq "ignore" 0 0 0
Condition0%0/3
not $@ or $self->on_error eq "ignore"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $@ or $self->on_error eq "ignore"
not $@ $self->on_error eq "ignore"
Truth table0%0/3
not(A) or B
A= not $@B= $self->on_error eq "ignore"
ABresult
1X1
011
000
72 0 my $msg = "While evaluating '$code' got error: $@";
73 0 ▶ log_fatal $msg if $self->on_error eq 'fatal';
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_error eq "fatal" 0 0 0
74 0 log_warn $msg;
75 0 return;
76 }
77  
78 1 1;
79  
80 __END__
« Treex/Block/Util/FixInvalidIDs.pm ↑ Summary Treex/Core/Node/Ordered.pm »