Treex/Block/Util/DefinedAttr.pm

filter: Statementstmt 27.6% 13 / 47 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 40.0% 2 / 5 Podpod 33.3% 1 / 3 totaltotal 17.3% 16 / 92 CC 18 SCAR 41.5
CC
18
Cov
16%
check_tree
110.0
BUILD
30.0
process_zone
30.0
CRAP 63.7
« Treex/Core/Scenario.pm ↑ Summary Treex/Core/Run.pm »
1 package Treex::Block::Util::DefinedAttr;
2 1 $Treex::Block::Util::DefinedAttr::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::Core::Block';
6  
7 1 has [qw(tnode anode nnode pnode)] => (
8 is => 'ro',
9 documentation => 'comma separated attributes of nodes on a given layer',
10 );
11  
12 1 has 'on_error' => (
13 is => 'ro',
14 isa => enum( [qw(warn die ignore)] ),
15 default => 'warn',
16 documentation => 'What to do if undefined attributes are found: warn (default), die, ignore',
17 );
18  
19 1 has 'message' => (
20 is => 'ro',
21 isa => 'Str',
22 default => '',
23 documentation => 'What to print',
24 );
25  
26 1 has fill => (
27 isa => 'Str',
28 is => 'ro',
29 default => 'undef',
30 documentation => 'Comma separated list of attribute values to be filled instead of undef. The default is "undef" which means Perl undef. If this list is shorter than ?node list, the last value is used for the rest. '
31 );
32  
33  
34 0 ▶sub BUILD {
Subroutine BUILD: not called CC=5 SCAR=34.0
Pod undocumented
35 0 my ($self) = @_;
36 0 ▶ if ( !$self->tnode && !$self->anode && !$self->nnode && !$self->pnode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->tnode or $self->anode or $self->nnode or $self->pnode) 0 0 0
Condition0%0/9
$self->tnode or $self->anode or $self->nnode or $self->pnode
l!l&&r!l&&!r
000
$self->tnode or $self->anode or $self->nnode
l!l&&r!l&&!r
000
$self->tnode or $self->anode
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->tnode or $self->anode or $self->nnode or $self->pnode
$self->tnode $self->anode $self->nnode $self->pnode
Truth table0%0/5
A or B or C or D
A= $self->tnodeB= $self->anodeC= $self->nnodeD= $self->pnode
ABCDresult
1XXX1
01XX1
001X1
00011
00000
37 0 log_fatal 'One of parameters tnode, anode, nnode, pnode must be specified.';
38 }
39 0 return;
40 }
41  
42 0 ▶sub process_zone {
Subroutine process_zone: not called CC=5 SCAR=34.0
Pod documented
43 0 my ( $self, $zone ) = @_;
44 0 ▶ if ( $self->anode ) { $self->check_tree( $zone, 'a', $self->anode ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->anode) 0 0 0
45 0 ▶ if ( $self->tnode ) { $self->check_tree( $zone, 't', $self->tnode ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tnode) 0 0 0
46 0 ▶ if ( $self->nnode ) { $self->check_tree( $zone, 'n', $self->nnode ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nnode) 0 0 0
47 0 ▶ if ( $self->pnode ) { $self->check_tree( $zone, 'p', $self->pnode ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pnode) 0 0 0
48 0 return;
49 }
50  
51 0 ▶sub check_tree {
Subroutine check_tree: not called CC=10 SCAR=47.0
Pod undocumented
52 0 my ( $self, $zone, $layer, $attrs ) = @_;
53 0 my $tree = $zone->get_tree($layer);
54 0 ▶ if ( !defined $tree ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tree) 0 0 0
55 0 log_warn "No $layer-tree in zone " . $zone->get_label();
56 0 return;
57 }
58  
59 0 foreach my $node ( $tree->get_descendants() ) {
60 0 my @fill_values = split /,/, $self->fill;
61  
62 # If $self->fill is an empty string, @fill_values will contain no items.
63 0 ▶ @fill_values = ('') if !@fill_values;
Branch: 1 branch
BranchTrueFalseTotal
unless @fill_values 0 0 0
64  
65 0 my $fill_value = shift @fill_values;
66 0 foreach my $name ( split /,/, $attrs ) {
67 0 my $orig_value = $node->get_attr($name);
68 0 ▶ if ( !defined $orig_value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $orig_value) 0 0 0
69 0 ▶ if ($self->on_error =~ /die|warn/){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->on_error =~ /die|warn/) 0 0 0
70 0 my $address = $node->get_address();
71 0 my $msg = "${layer}node\t$address\tundefined attr_name=$name\t" . $self->message;
72 0 ▶ log_fatal($msg) if $self->on_error eq 'die';
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_error eq "die" 0 0 0
73 0 log_warn($msg);
74 }
75 0 ▶ $node->set_attr($name, $fill_value) if $fill_value ne 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $fill_value ne "undef" 0 0 0
76 }
77 0 ▶ $fill_value = shift @fill_values if @fill_values;
Branch: 1 branch
BranchTrueFalseTotal
if @fill_values 0 0 0
78 }
79 }
80 0 return;
81 }
82  
83 1 1;
84  
85 __END__
« Treex/Core/Scenario.pm ↑ Summary Treex/Core/Run.pm »