line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::AST::Modulus; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Calculate the modulus of a series of values |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
48702
|
use strict; |
|
23
|
|
|
|
|
46
|
|
|
23
|
|
|
|
|
768
|
|
7
|
23
|
|
|
23
|
|
99
|
use warnings; |
|
23
|
|
|
|
|
30
|
|
|
23
|
|
|
|
|
543
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
88
|
use utf8; |
|
23
|
|
|
|
|
28
|
|
|
23
|
|
|
|
|
113
|
|
10
|
23
|
|
|
23
|
|
456
|
use parent 'Dallycot::AST'; |
|
23
|
|
|
|
|
32
|
|
|
23
|
|
|
|
|
159
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
1373
|
use Promises qw(deferred); |
|
23
|
|
|
|
|
41
|
|
|
23
|
|
|
|
|
123
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub to_string { |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
0
|
|
|
|
|
|
return join( " mod ", map { $_->to_string } @$self ); |
|
0
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub to_rdf { |
20
|
0
|
|
|
0
|
0
|
|
my($self, $model) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
return $model -> apply( |
23
|
|
|
|
|
|
|
$model -> meta_uri('loc:modulus'), |
24
|
|
|
|
|
|
|
[ @$self ], |
25
|
|
|
|
|
|
|
{} |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
# my $bnode = $model->bnode; |
28
|
|
|
|
|
|
|
# $model -> add_type($bnode, 'loc:Modulus'); |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# $model -> add_list($bnode, 'loc:expressions', |
31
|
|
|
|
|
|
|
# map { $_ -> to_rdf($model) } @$self |
32
|
|
|
|
|
|
|
# ); |
33
|
|
|
|
|
|
|
# return $bnode; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub execute { |
37
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my @expressions = @$self; |
40
|
|
|
|
|
|
|
return $engine->execute( ( shift @expressions ), ['Numeric'] )->then( |
41
|
|
|
|
|
|
|
sub { |
42
|
0
|
|
|
0
|
|
|
my ($left_value) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $d = deferred; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->process_loop( |
47
|
|
|
|
|
|
|
$engine, $d, |
48
|
|
|
|
|
|
|
base => $left_value, |
49
|
|
|
|
|
|
|
expressions => \@expressions |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $d; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub process_loop { |
58
|
0
|
|
|
0
|
0
|
|
my ( $self, $engine, $d, %state ) = @_; |
59
|
0
|
0
|
|
|
|
|
my ( $left_value, $right_expr, @expressions ) |
60
|
0
|
|
|
|
|
|
= ( $state{base}, @{ $state{expressions} || [] } ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( !@expressions ) { |
63
|
|
|
|
|
|
|
$engine->execute( $right_expr, ['Numeric'] )->done( |
64
|
|
|
|
|
|
|
sub { |
65
|
0
|
|
|
0
|
|
|
my ($right_value) = @_; |
66
|
0
|
|
|
|
|
|
$d->resolve( |
67
|
|
|
|
|
|
|
Dallycot::Value::Numeric->new( $left_value->value->copy->bmod( $right_value->value ) ) ); |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
sub { |
70
|
0
|
|
|
0
|
|
|
$d->reject(@_); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
|
|
|
|
|
|
$engine->execute( $right_expr, ['Numeric'] )->done( |
76
|
|
|
|
|
|
|
sub { |
77
|
0
|
|
|
0
|
|
|
my ($right_value) = @_; |
78
|
0
|
|
|
|
|
|
$left_value = $left_value->copy->bmod( $right_value->value ); |
79
|
0
|
0
|
|
|
|
|
if ( $left_value->is_zero ) { |
80
|
0
|
|
|
|
|
|
$d->resolve( Dallycot::Value::Numeric->new($left_value) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
|
$self->process_loop( |
84
|
|
|
|
|
|
|
$engine, $d, |
85
|
|
|
|
|
|
|
base => $left_value, |
86
|
|
|
|
|
|
|
expressions => \@expressions |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
sub { |
91
|
0
|
|
|
0
|
|
|
$d->reject(@_); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |