File Coverage

blib/lib/Dallycot/AST/Product.pm
Criterion Covered Total %
statement 15 30 50.0
branch n/a
condition n/a
subroutine 5 9 55.5
pod 0 3 0.0
total 20 42 47.6


line stmt bran cond sub pod time code
1             package Dallycot::AST::Product;
2             our $AUTHORITY = 'cpan:JSMITH';
3              
4             # ABSTRACT: Calculates the product of a series of values
5              
6 23     23   11923 use strict;
  23         33  
  23         683  
7 23     23   88 use warnings;
  23         30  
  23         438  
8              
9 23     23   75 use utf8;
  23         29  
  23         100  
10 23     23   393 use parent 'Dallycot::AST';
  23         34  
  23         105  
11              
12 23     23   1027 use Readonly;
  23         32  
  23         6123  
13              
14             Readonly my $NUMERIC => ['Numeric'];
15              
16             sub to_string {
17 0     0 0   my ($self) = @_;
18              
19 0           return "(" . join( "*", map { $_->to_string } @{$self} ) . ")";
  0            
  0            
20             }
21              
22             sub to_rdf {
23 0     0 0   my($self, $model) = @_;
24              
25             #
26             # node -> expression_set -> [ ... ]
27             #
28 0           return $model -> apply(
29             $model -> meta_uri('loc:product'),
30             [ @$self ],
31             {}
32             );
33             # my $bnode = $model->bnode;
34             # $model -> add_type($bnode, 'loc:Product');
35             #
36             # foreach my $expr (@$self) {
37             # $model -> add_expression($bnode, $expr);
38             # }
39             # return $bnode;
40             }
41              
42             sub execute {
43 0     0 0   my ( $self, $engine ) = @_;
44              
45 0           return $engine->collect( map { [ $_, $NUMERIC ] } @$self )->then(
46             sub {
47 0     0     my (@values) = map { $_->value } @_;
  0            
48              
49 0           my $acc = ( pop @values )->copy;
50              
51 0           while (@values) {
52 0           $acc *= ( pop @values );
53             }
54              
55 0           return Dallycot::Value::Numeric->new($acc);
56             }
57 0           );
58             }
59              
60             1;