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/VarTypes.pm ↑ Summary blib/lib/YATT/Lite/CLI/Render.pm »
1 package YATT::Lite::VarMaker; sub MY () {__PACKAGE__}
2 77 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 77 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 77 ▶use base qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 77 ▶use YATT::Lite::MFields qw/_type_alias
Subroutine BEGIN: called CC=1 SCAR=0.0
6 77 _curline/;
7  
8 77 ▶use YATT::Lite::VarTypes qw(:type :VSLOT);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 77 ▶use YATT::Lite::Util qw(lexpand default);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # XXX: Should integrated to VarTypes.
12 522 ▶sub default_arg_type {'text'}
Subroutine default_arg_type: called CC=1 SCAR=0.0
Pod undocumented
13 1916 ▶sub default_type_alias {
Subroutine default_type_alias: called CC=1 SCAR=0.0
Pod undocumented
14 1916 qw(value scalar
15 flag bool
16 boolean bool);
17 }
18  
19 1916 ▶sub after_new {
Subroutine after_new: called CC=1 SCAR=0.0
Pod documented
20 1916 my MY $self = shift;
21 1916 $self->SUPER::after_new;
22 1916 $self->{_type_alias} = { $self->default_type_alias };
23 1916 $self;
24 }
25  
26 # Note: To use mkvar_at(), derived class must implement
27 # _error() and _tmpl_file_line().
28 # Currently, YATT::Lite::LRXML and YATT::Lite::CGen uses this.
29 4192 ▶sub mkvar_at {
Subroutine mkvar_at: called CC=3 SCAR=11.0
Pod undocumented
30 4192 (my MY $self, my ($lineno, $type, $name, @args)) = @_;
31  
32 4192 my ($typerec, $sub) = $self->_mk_typerec($type, $lineno, $name);
33  
34 4191 my $var = $sub->()->new($typerec, $name, @args);
35 4191 ▶ $var->[VSLOT_LINENO] //= $lineno //= $self->{_curline};
Condition100%6/6
$var->[3] //= ($lineno //= $self->{"_curline"})
l!l&&r!l&&!r
6172690884
$lineno //= $self->{"_curline"}
l!l&&r!l&&!r
632627884
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
36  
37 # $self->set_dflag_default_to($var, $var->[VSLOT_DFLAG], $var->[VSLOT_DEFAULT]);
38  
39 4191 $var;
40 }
41  
42 1 ▶sub set_var_type {
Subroutine set_var_type: called CC=1 SCAR=0.0
Pod undocumented
43 1 (my MY $self, my ($var, $type)) = @_;
44 1 $var->type(scalar $self->_mk_typerec($type));
45 }
46  
47 4193 ▶sub _mk_typerec {
Subroutine _mk_typerec: called CC=6 SCAR=17.9
48 4193 (my MY $self, my ($type, $lineno, $name)) = @_;
49  
50 4193 ▶ ($type, my @subtype) = ref $type ? lexpand($type) : split /:/, $type || '';
Branch: 1 branch
BranchTrueFalseTotal
ref $type ? : 10 4183 4193
Condition100%2/2
$type || ''
l!l
3661522
MC/DC100%1/1
$type || ''
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
51 #
52 4193 ▶ $type ||= $self->default_arg_type;
Condition66%2/3
$type ||= $self->default_arg_type
l!l&&r!l&&!r
36715220
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
53 4193 $type = default($self->{_type_alias}{$type}, $type);
54  
55 4193 my $typerec = [$type, @subtype];
56  
57 4193 ▶ wantarray ? ($typerec, do {
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4192 1 4193
58 4192 ▶ 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) } 4191 1 4192
59 1 my %opts = ($self->_tmpl_file_line($lineno));
60 1 die $self->_error(\%opts, q|Unknown type '%s' for variable '%s'|
61 , $type, $name);
62 };
63 }) : $typerec;
64 }
65  
66 1513 ▶sub parse_type_dflag_default {
Subroutine parse_type_dflag_default: called CC=2 SCAR=6.9
Pod undocumented
67 1513 ▶ split m{([|/?!])}, $_[1] || '', 2;
Condition100%2/2
$_[1] || ''
l!l
1044469
MC/DC100%1/1
$_[1] || ''
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
68 }
69  
70 1548 ▶sub set_dflag_default_to {
Subroutine set_dflag_default_to: called CC=4 SCAR=13.9
Pod undocumented
71 1548 (my MY $self, my ($var, $dflag, $default)) = @_;
72 1548 ▶ if (not $dflag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dflag) 1502 46 1548
73 1502 ($dflag, $default) = $var->default_dflag_default;
74 }
75 1548 ▶ $var->[VSLOT_DFLAG] = $dflag if $dflag;
Branch: 1 branch
BranchTrueFalseTotal
if $dflag 67 1481 1548
76 1548 ▶ if (defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default) 67 1481 1548
77 67 $var->[VSLOT_DEFAULT] = $self->_parse_text_entities($default);
78 67 $var->[VSLOT_DEFAULT_EXPR] = $default;
79 }
80 }
81  
82 77 1;
« blib/lib/YATT/Lite/VarTypes.pm ↑ Summary blib/lib/YATT/Lite/CLI/Render.pm »