| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBR::Config::Trans::Percent; |
|
2
|
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
112
|
use strict; |
|
|
18
|
|
|
|
|
39
|
|
|
|
18
|
|
|
|
|
1091
|
|
|
4
|
18
|
|
|
18
|
|
102
|
use base 'DBR::Config::Trans'; |
|
|
18
|
|
|
|
|
116
|
|
|
|
18
|
|
|
|
|
6748
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
0
|
|
|
0
|
0
|
0
|
sub new { die "Should not get here" } |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub forward{ |
|
10
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
|
11
|
1
|
|
|
|
|
4
|
my $rawvalue = shift; |
|
12
|
1
|
|
|
|
|
9
|
return bless( [$rawvalue] , 'DBR::_PERCENT'); |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub backward{ |
|
16
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
|
17
|
2
|
|
|
|
|
4
|
my $value = shift; |
|
18
|
|
|
|
|
|
|
|
|
19
|
2
|
50
|
33
|
|
|
17
|
return undef unless defined($value) && length($value); |
|
20
|
|
|
|
|
|
|
|
|
21
|
2
|
50
|
|
|
|
8
|
if( ref($value) eq 'DBR::_PERCENT' ){ # looks like it's a percent object |
|
22
|
0
|
|
|
|
|
0
|
return $value->value; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
9
|
$value =~ s/[^\d\.-]//g; # strip everything but digit and . |
|
26
|
2
|
100
|
|
|
|
13
|
unless( $value =~ /^\-?\d*\.?\d+$/ ){ |
|
27
|
1
|
|
|
|
|
11
|
$self->_error('invalid value specified'); |
|
28
|
1
|
|
|
|
|
4
|
return (); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
5
|
return $value; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
package DBR::_PERCENT; |
|
35
|
|
|
|
|
|
|
|
|
36
|
18
|
|
|
18
|
|
126
|
use strict; |
|
|
18
|
|
|
|
|
41
|
|
|
|
18
|
|
|
|
|
545
|
|
|
37
|
18
|
|
|
18
|
|
116
|
use Carp; |
|
|
18
|
|
|
|
|
49
|
|
|
|
18
|
|
|
|
|
6558
|
|
|
38
|
|
|
|
|
|
|
use overload |
|
39
|
|
|
|
|
|
|
#values |
|
40
|
0
|
|
|
0
|
|
0
|
'""' => sub { $_[0]->format }, |
|
41
|
1
|
|
|
1
|
|
74
|
'0+' => sub { $_[0]->value }, |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#operators |
|
44
|
0
|
|
|
0
|
|
0
|
'+' => sub { new($_[0]->value + $_[1]) }, |
|
45
|
|
|
|
|
|
|
'-' => sub { |
|
46
|
0
|
|
|
0
|
|
0
|
my ($a,$b) = ($_[0]->value, $_[1]); |
|
47
|
0
|
0
|
|
|
|
0
|
new ($_[2] ? $b - $a : $a - $b); |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
|
0
|
'*' => sub { new($_[0]->value * $_[1]) }, |
|
51
|
|
|
|
|
|
|
'/' => sub { |
|
52
|
0
|
|
|
0
|
|
0
|
my ($a,$b) = ($_[0]->value, $_[1] ); |
|
53
|
0
|
0
|
|
|
|
0
|
new ($_[2] ? $b / $a : $a / $b); |
|
54
|
|
|
|
|
|
|
}, |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
|
0
|
'fallback' => 1, |
|
57
|
|
|
|
|
|
|
'nomethod' => sub {croak "Percent object: Invalid operation '$_[3]' The ways in which you can use percent objects is restricted"} |
|
58
|
18
|
|
|
18
|
|
120
|
; |
|
|
18
|
|
|
|
|
39
|
|
|
|
18
|
|
|
|
|
403
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
*TO_JSON = \&format; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub value { |
|
63
|
1
|
50
|
|
1
|
|
6
|
return '' unless defined($_[0][0]); |
|
64
|
1
|
|
|
|
|
5
|
return $_[0][0] |
|
65
|
|
|
|
|
|
|
}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub format { |
|
68
|
0
|
0
|
|
0
|
|
|
return '' unless defined($_[0][0]); |
|
69
|
0
|
|
|
|
|
|
$_[0]->value . '%' |
|
70
|
|
|
|
|
|
|
}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#utilities |
|
73
|
0
|
|
0
|
0
|
|
|
sub new{ bless([ $_[1] || $_[0] ],'DBR::_PERCENT') } # will work OO or functional |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |