File Coverage

blib/lib/DTL/Fast/Expression/Operator/Binary/Div.pm
Criterion Covered Total %
statement 22 23 95.6
branch 3 4 75.0
condition 6 11 54.5
subroutine 6 6 100.0
pod 0 1 0.0
total 37 45 82.2


line stmt bran cond sub pod time code
1             package DTL::Fast::Expression::Operator::Binary::Div;
2 3     3   1865 use strict; use utf8; use warnings FATAL => 'all';
  3     3   4  
  3     3   73  
  3         8  
  3         5  
  3         14  
  3         57  
  3         3  
  3         108  
3 3     3   9 use parent 'DTL::Fast::Expression::Operator::Binary';
  3         3  
  3         15  
4              
5             $DTL::Fast::OPS_HANDLERS{'/'} = __PACKAGE__;
6              
7 3     3   196 use Scalar::Util qw(looks_like_number);
  3         5  
  3         557  
8              
9             sub dispatch
10             {
11 46     46 0 47 my( $self, $arg1, $arg2, $context) = @_;
12 46         48 my ($arg1_type, $arg2_type) = (ref $arg1, ref $arg2);
13 46         38 my $result = 0;
14              
15 46 100 66     166 if( looks_like_number($arg1) and looks_like_number($arg2))
    50          
16             {
17 44         47 $result = ($arg1 / $arg2);
18             }
19             elsif( UNIVERSAL::can($arg1, 'div'))
20             {
21 0         0 $result = $arg1->div($arg2);
22             }
23             else
24             {
25 2   50     41 die $self->get_render_error(
      50        
      50        
      50        
26             $context,
27             sprintf(
28             "Don't know how to divide %s (%s) by %s (%s)"
29             , $arg1 // 'undef'
30             , $arg1_type || 'SCALAR'
31             , $arg2 // 'undef'
32             , $arg2_type || 'SCALAR'
33             )
34             );
35             }
36              
37 44         84 return $result;
38             }
39              
40             1;