Treex/Core/RememberArgs.pm

filter: Statementstmt 28.5% 8 / 28 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 1 / 4 Podpod 0.0% 0 / 1 totaltotal 20.9% 9 / 43 CC 7 SCAR 36.8
CC
7
Cov
21%
__ANON__
56.0
__ANON__
2.0
BEGIN
1.0
CRAP 39.6
« Treex/Core/Block.pm ↑ Summary Treex/Core/Node/A.pm »
1 package Treex::Core::RememberArgs;
2 1 $Treex::Core::RememberArgs::VERSION = '2.20210102';
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 has args => (
6 is => 'ro',
7 isa => 'HashRef',
8 writer => '_set_args',
9 0 ▶ default => sub {return {};},
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 1 );
11  
12 1 has args_str => (
13 is => 'ro',
14 isa => 'Str',
15 writer => '_set_args_str',
16 default => '',
17 );
18  
19 # Empty BUILD is needed, so we can use "after BUILD".
20 # "after BUILD" is needed because we cannot (and don't want to)
21 # override the BUILD which may be present in the class which will consume this role.
22 # See http://rjbs.manxome.org/rubric/entry/1864
23 0 ▶sub BUILD {}
Subroutine BUILD: not called CC=1 SCAR=0.0
Pod undocumented
24 0 ▶after BUILD => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
25 0 my ($self, $args) = @_;
26 0 $self->_set_args($args);
27 0 my $str = '';
28  
29 # The method which consumes this role may implement
30 # its BUILD where a default values of some attributes
31 # are set. Let's put back these values into $args.
32 0 foreach my $key (keys %{$self}) {
33 0 ▶ next if $key =~ /^args(_str)?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^args(_str)?$/ 0 0 0
34 0 my $value = $self->{$key};
35 0 ▶ next if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
36 0 ▶ next if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
37 0 $args->{$key} = $value;
38 }
39  
40 # Prepare a single-quoted string representation of all args.
41 0 ▶ while (my ($key, $value) = each %{$args}){
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args;}) 0 0 0
42 0 ▶ if ($value =~ /\s/){
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\s/) 0 0 0
43 0 $value =~ s/'/\\'/g;
44 0 $value = "'$value'";
45 }
46 0 $str .= "$key=$value ";
47 }
48 0 $str =~ s/ $//;
49 0 $self->_set_args_str($str);
50 0 return;
51 1 };
52  
53 1 1;
54  
55 __END__
« Treex/Core/Block.pm ↑ Summary Treex/Core/Node/A.pm »