blib/lib/YATT/Lite/VarMaker.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 12 / 12 Conditioncond 92.3% 12 / 13 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 100% 14 / 14 Podpod 14.2% 1 / 7 totaltotal 91.2% 94 / 103 CC 12 SCAR 11.0
CC
12
Cov
99%
_mk_typerec
6.0
set_dflag_default_to
4.0
mkvar_at
3.0
CRAP 3.0
« blib/lib/YATT/Lite/CLI/Render.pm ↑ Summary blib/lib/YATT/Lite/CLI/GenPerl.pm »
1 package YATT::Lite::VarMaker; sub MY () {__PACKAGE__}
2 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 49 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 49 ▶use base qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 49 ▶use YATT::Lite::MFields qw/_type_alias
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 _curline/;
7  
8 49 ▶use YATT::Lite::VarTypes qw(:type :VSLOT);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 49 ▶use YATT::Lite::Util qw(lexpand default);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # XXX: Should integrated to VarTypes.
12 408 ▶sub default_arg_type {'text'}
Subroutine default_arg_type: called CC=1 SCAR=0.0
Pod undocumented
13 1385 ▶sub default_type_alias {
Subroutine default_type_alias: called CC=1 SCAR=0.0
Pod undocumented
14 1385 qw(value scalar
15 flag bool
16 boolean bool
17 expr code);
18 }
19  
20 1385 ▶sub after_new {
Subroutine after_new: called CC=1 SCAR=0.0
Pod documented
21 1385 my MY $self = shift;
22 1385 $self->SUPER::after_new;
23 1385 $self->{_type_alias} = { $self->default_type_alias };
24 1385 $self;
25 }
26  
27 # Note: To use mkvar_at(), derived class must implement
28 # _error() and _tmpl_file_line().
29 # Currently, YATT::Lite::LRXML and YATT::Lite::CGen uses this.
30 3011 ▶sub mkvar_at {
Subroutine mkvar_at: called CC=3 SCAR=11.0
Pod undocumented
31 3011 (my MY $self, my ($lineno, $type, $name, @args)) = @_;
32  
33 3011 my ($typerec, $sub) = $self->_mk_typerec($type, $lineno, $name);
34  
35 3010 my $var = $sub->()->new($typerec, $name, @args);
36 3010 ▶ $var->[VSLOT_LINENO] //= $lineno //= $self->{_curline};
Condition100%6/6
$var->[3] //= ($lineno //= $self->{"_curline"})
l!l&&r!l&&!r
4951870645
$lineno //= $self->{"_curline"}
l!l&&r!l&&!r
81862645
MC/DC100%2/2
$var->[3] //= ($lineno //= $self->{"_curline"})
$var->[3] ($lineno //= $self->{"_curline"})
MC/DC100%2/2
$lineno //= $self->{"_curline"}
$lineno $self->{"_curline"}
Truth table100%3/3
A //= B
A= $var->[3]B= ($lineno //= $self->{"_curline"})
ABresult
1X1
011
000
Truth table100%3/3
A //= B
A= $linenoB= $self->{"_curline"}
ABresult
1X1
011
000
37  
38 # $self->set_dflag_default_to($var, $var->[VSLOT_DFLAG], $var->[VSLOT_DEFAULT]);
39  
40 3010 $var;
41 }
42  
43 1 ▶sub set_var_type {
Subroutine set_var_type: called CC=1 SCAR=0.0
Pod undocumented
44 1 (my MY $self, my ($var, $type)) = @_;
45 1 $var->type(scalar $self->_mk_typerec($type));
46 }
47  
48 3012 ▶sub _mk_typerec {
Subroutine _mk_typerec: called CC=6 SCAR=17.9
49 3012 (my MY $self, my ($type, $lineno, $name)) = @_;
50  
51 3012 ▶ ($type, my @subtype) = ref $type ? lexpand($type) : split /:/, $type || '';
Branch: 1 branch
BranchTrueFalseTotal
ref $type ? : 9 3003 3012
Condition100%2/2
$type || ''
l!l
2595408
MC/DC100%1/1
$type || ''
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
52 #
53 3012 ▶ $type ||= $self->default_arg_type;
Condition66%2/3
$type ||= $self->default_arg_type
l!l&&r!l&&!r
26044080
MC/DC0%0/2
$type ||= $self->default_arg_type
$type $self->default_arg_type
Truth table66%2/3
A ||= B
A= $typeB= $self->default_arg_type
ABresult
1X1
011
000
54 3012 $type = default($self->{_type_alias}{$type}, $type);
55  
56 3012 my $typerec = [$type, @subtype];
57  
58 3012 ▶ wantarray ? ($typerec, do {
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3011 1 3012
59 3011 ▶ my $sub = $self->can("t_$type") or do {
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("t_$type") or do { my(%opts) = $self->_tmpl_file_line($lineno); die $self->_error(\%opts, "Unknown type '%s' for variable '%s'", $type, $name) } 3010 1 3011
60 1 my %opts = ($self->_tmpl_file_line($lineno));
61 1 die $self->_error(\%opts, q|Unknown type '%s' for variable '%s'|
62 , $type, $name);
63 };
64 }) : $typerec;
65 }
66  
67 1125 ▶sub parse_type_dflag_default {
Subroutine parse_type_dflag_default: called CC=2 SCAR=6.9
Pod undocumented
68 1125 ▶ split m{([|/?!])}, $_[1] || '', 2;
Condition100%2/2
$_[1] || ''
l!l
749376
MC/DC100%1/1
$_[1] || ''
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
69 }
70  
71 1133 ▶sub set_dflag_default_to {
Subroutine set_dflag_default_to: called CC=4 SCAR=13.9
Pod undocumented
72 1133 (my MY $self, my ($var, $dflag, $default)) = @_;
73 1133 ▶ if (not $dflag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dflag) 1093 40 1133
74 1093 ($dflag, $default) = $var->default_dflag_default;
75 }
76 1133 ▶ $var->[VSLOT_DFLAG] = $dflag if $dflag;
Branch: 1 branch
BranchTrueFalseTotal
if $dflag 58 1075 1133
77 1133 ▶ if (defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 58 1075 1133
78 58 $var->[VSLOT_DEFAULT] = $self->_parse_text_entities($default);
79 58 $var->[VSLOT_DEFAULT_EXPR] = $default;
80 }
81 }
82  
83 49 1;
« blib/lib/YATT/Lite/CLI/Render.pm ↑ Summary blib/lib/YATT/Lite/CLI/GenPerl.pm »