File Coverage

blib/lib/DTL/Fast/Tag/Widthratio.pm
Criterion Covered Total %
statement 30 32 93.7
branch 4 6 66.6
condition 0 2 0.0
subroutine 7 7 100.0
pod 0 2 0.0
total 41 49 83.6


line stmt bran cond sub pod time code
1             package DTL::Fast::Tag::Widthratio;
2 2     2   1294 use strict; use utf8; use warnings FATAL => 'all';
  2     2   4  
  2     2   52  
  2         10  
  2         4  
  2         12  
  2         49  
  2         4  
  2         71  
3 2     2   9 use parent 'DTL::Fast::Tag::Simple';
  2         4  
  2         12  
4              
5             $DTL::Fast::TAG_HANDLERS{'widthratio'} = __PACKAGE__;
6              
7 2     2   121 use DTL::Fast::Utils;
  2         3  
  2         635  
8              
9             #@Override
10             sub parse_parameters
11             {
12 3     3 0 5 my $self = shift;
13              
14 3 50       32 if( $self->{'parameter'} =~ /^\s*(.+?)(?:\s+as\s+([^\s]+))?\s*$/s )
15             {
16 3         7 $self->{'target_name'} = $2;
17            
18 3         16 $self->{'sources'} = $self->parse_sources($1);
19            
20             die $self->get_parse_error(
21             sprintf(
22             "Three arguments should be passed to widthratio: %s %s"
23             , $self->{'parameter'} // 'undef'
24 0         0 , scalar @{$self->{'sources'}}
25             )
26 3 50 0     5 ) if scalar @{$self->{'sources'}} != 3;
  3         10  
27             }
28             else
29             {
30 0         0 die die $self->get_parse_error("Unable to parse ratio parameters $self->{'parameter'}");
31             }
32            
33 3         7 return $self;
34             }
35              
36             #@Override
37             sub render
38             {
39 3     3 0 10 my $self = shift;
40 3         3 my $context = shift;
41              
42 3         5 my $sources = $self->{'sources'};
43 3         12 my $result = int(
44             $sources->[0]->render($context)
45             / $sources->[1]->render($context)
46             * $sources->[2]->render($context)
47             );
48            
49 3 100       9 if( $self->{'target_name'} )
50             {
51 1         5 $context->set($self->{'target_name'} => $result);
52 1         1 $result = '';
53             }
54            
55 3         14 return $result;
56             }
57              
58             1;