File Coverage

blib/lib/YATT/Lite/VarMaker.pm
Criterion Covered Total %
statement 34 34 100.0
branch 4 4 100.0
condition 10 11 90.9
subroutine 10 10 100.0
pod 1 4 25.0
total 59 63 93.6


line stmt bran cond sub pod time code
1             package YATT::Lite::VarMaker; sub MY () {__PACKAGE__}
2 11     11   65 use strict;
  11         24  
  11         336  
3 11     11   56 use warnings qw(FATAL all NONFATAL misc);
  11         20  
  11         372  
4 11     11   56 use base qw(YATT::Lite::Object);
  11         18  
  11         3598  
5 11         92 use fields qw/type_alias
6 11     11   57 curline/;
  11         19  
7              
8 11     11   7521 use YATT::Lite::VarTypes qw(:type :VSLOT);
  11         25  
  11         2724  
9 11     11   60 use YATT::Lite::Util qw(lexpand default);
  11         21  
  11         3652  
10              
11             # XXX: Should integrated to VarTypes.
12 168     168 0 549 sub default_arg_type {'text'}
13             sub default_type_alias {
14 495     495 0 2868 qw(value scalar
15             flag bool
16             boolean bool
17             expr code);
18             }
19              
20             sub after_new {
21 495     495 1 770 my MY $self = shift;
22 495         1360 $self->SUPER::after_new;
23 495         1081 $self->{type_alias} = { $self->default_type_alias };
24 495         1371 $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             sub mkvar_at {
31 1233     1233 0 3442 (my MY $self, my ($lineno, $type, $name, @args)) = @_;
32 1233 100 100     5661 ($type, my @subtype) = ref $type ? lexpand($type) : split /:/, $type || '';
33             #
34 1233   66     3264 $type ||= $self->default_arg_type;
35 1233         4830 $type = default($self->{type_alias}{$type}, $type);
36              
37 1233 100       6234 my $sub = $self->can("t_$type") or do {
38 1         5 my %opts = ($self->_tmpl_file_line($lineno));
39 1         7 die $self->_error(\%opts, q|Unknown type '%s' for variable '%s'|
40             , $type, $name);
41             };
42              
43 1232         7658 my $var = $sub->()->new([$type, @subtype], $name, @args);
44 1232   100     7553 $var->[VSLOT_LINENO] //= $lineno //= $self->{curline};
      100        
45 1232         4573 $var;
46             }
47              
48             1;