line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::DeferredPartial::Op::Binary; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use Sub::DeferredPartial(); @ISA = 'Sub::DeferredPartial'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1241
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %Ops = map { $_ => eval "sub { \$_[0] $_ \$_[1] }" } |
9
|
|
|
|
|
|
|
qw( + - * / % ** << >> x . & | ^ <=> cmp < <= > >= == != lt le gt ge eq ne ); |
10
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
13
|
|
|
|
|
|
|
{ |
14
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
15
|
0
|
|
|
|
|
|
my $Op = shift; |
16
|
0
|
|
|
|
|
|
my $Op1 = shift; |
17
|
0
|
|
|
|
|
|
my $Op2 = shift; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
confess "Operator '$Op' not implemented" unless exists $Ops{$Op}; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
bless { Op => $Op, Op1 => $Op1, Op2 => $Op2 } => $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
sub Apply |
25
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
my %Args = @_; |
29
|
0
|
|
|
|
|
|
my $Free = $self->Free; |
30
|
0
|
|
|
|
|
|
my %Args1 = (); my $n1 = 0; my $Free1 = $self->{Op1}->Free; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my %Args2 = (); my $n2 = 0; my $Free2 = $self->{Op2}->Free; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
while ( my ( $k, $v ) = each %Args ) |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
0
|
|
|
|
|
confess "Not a free parameter: $k" unless exists $Free->{$k}; |
36
|
0
|
0
|
|
|
|
|
$Args1{$k} = $Args{$k}, $n1++ if exists $Free1->{$k}; |
37
|
0
|
0
|
|
|
|
|
$Args2{$k} = $Args{$k}, $n2++ if exists $Free2->{$k}; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
0
|
|
|
|
|
my $Op1 = $n1 ? $self->{Op1}->Apply( %Args1 ) : $self->{Op1}; |
40
|
0
|
0
|
|
|
|
|
my $Op2 = $n2 ? $self->{Op2}->Apply( %Args2 ) : $self->{Op2}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return ref( $self )->new( $self->{Op}, $Op1, $Op2 ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
45
|
|
|
|
|
|
|
sub Eval |
46
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $Ops{$self->{Op}}->( $self->{Op1}->Eval, $self->{Op2}->Eval ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
53
|
|
|
|
|
|
|
sub Free |
54
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return { %{$self->{Op1}->Free}, %{$self->{Op2}->Free} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
sub Describe |
62
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return "( $self->{Op1} $self->{Op} $self->{Op2} )"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Sub::DeferredPartial::Op::Binary - Binary operator. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Steffen Goeldner |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 COPYRIGHT |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Copyright (c) 2004 Steffen Goeldner. All rights reserved. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
84
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |