line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::DeferredPartial::Op::Unary; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use Sub::DeferredPartial(); @ISA = 'Sub::DeferredPartial'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
756
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %Ops = map { $_ => eval "sub { $_ \$_[0] }" } |
9
|
|
|
|
|
|
|
qw( neg ! ~ abs sqrt exp log sin cos ); |
10
|
|
|
|
|
|
|
$Ops{neg} = eval "sub { - \$_[0] }"; |
11
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
12
|
|
|
|
|
|
|
sub new |
13
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
{ |
15
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
16
|
0
|
|
|
|
|
|
my $Op = shift; |
17
|
0
|
|
|
|
|
|
my $Op1 = shift; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
confess "Operator '$Op' not implemented" unless exists $Ops{$Op}; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
bless { Op => $Op, Op1 => $Op1 } => $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
sub Apply |
25
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return ref( $self )->new( $self->{Op}, $self->{Op1}->Apply( @_ ) ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
32
|
|
|
|
|
|
|
sub Eval |
33
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $Ops{$self->{Op}}->( $self->{Op1}->Eval ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
sub Free |
41
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $self->{Op1}->Free; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
48
|
|
|
|
|
|
|
sub Describe |
49
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return "( $self->{Op} $self->{Op1} )"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Sub::DeferredPartial::Op::Unary - Unary operator. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 AUTHOR |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Steffen Goeldner |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 COPYRIGHT |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Copyright (c) 2004 Steffen Goeldner. All rights reserved. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
71
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |