| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Math::Units::PhysicalValue::AutoUnit; |
|
2
|
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
80
|
use strict; |
|
|
14
|
|
|
|
|
29
|
|
|
|
14
|
|
|
|
|
472
|
|
|
4
|
14
|
|
|
14
|
|
78
|
use Carp; |
|
|
14
|
|
|
|
|
24
|
|
|
|
14
|
|
|
|
|
1106
|
|
|
5
|
14
|
|
|
14
|
|
33969
|
use Math::Algebra::Symbols; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use overload |
|
7
|
|
|
|
|
|
|
'+' => \&au_add, |
|
8
|
|
|
|
|
|
|
'-' => \&au_sub, |
|
9
|
|
|
|
|
|
|
'/' => \&au_div, |
|
10
|
|
|
|
|
|
|
'*' => \&au_mul, |
|
11
|
|
|
|
|
|
|
'**' => \&au_mulmul, |
|
12
|
|
|
|
|
|
|
'sqrt' => \&au_sqrt, |
|
13
|
|
|
|
|
|
|
'eq' => \&au_eq, |
|
14
|
|
|
|
|
|
|
'""' => \&au_print; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 1.0005; # PV::AU diverges from PV here |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# new {{{ |
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
|
|
|
|
|
|
my $class = shift; |
|
21
|
|
|
|
|
|
|
my $unit = shift; |
|
22
|
|
|
|
|
|
|
my $this = bless {unit=>1}, $class; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if( $unit =~ m/[^a-zA-Z]/i ) { |
|
25
|
|
|
|
|
|
|
my %unities = (); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
while( $unit =~ m/([a-zA-Z]+)/g ) { |
|
28
|
|
|
|
|
|
|
my $xxu = "xx$1"; |
|
29
|
|
|
|
|
|
|
unless( $unities{$xxu} ) { |
|
30
|
|
|
|
|
|
|
$unities{$xxu} = symbols($xxu); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $obj; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$unit =~ s/([a-zA-Z]+)/\$unities{"xx$1"}/g; |
|
37
|
|
|
|
|
|
|
$unit = "\$obj = $unit"; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
eval $unit; |
|
40
|
|
|
|
|
|
|
die $@ if $@; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# use Data::Dumper; |
|
43
|
|
|
|
|
|
|
# warn "$obj"; |
|
44
|
|
|
|
|
|
|
# die Dumper( \%unities, $unit, $obj ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$this->{unit} = $obj; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} elsif( $unit =~ m/[a-zA-Z]/ ) { |
|
49
|
|
|
|
|
|
|
$this->{unit} = symbols("xx$unit"); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return $this; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
# }}} |
|
56
|
|
|
|
|
|
|
# au_mul {{{ |
|
57
|
|
|
|
|
|
|
sub au_mul { |
|
58
|
|
|
|
|
|
|
my ($lhs, $rhs) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return bless { unit=>($lhs->{unit} * $rhs->{unit}) }, ref $lhs; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
# }}} |
|
63
|
|
|
|
|
|
|
# au_mulmul {{{ |
|
64
|
|
|
|
|
|
|
sub au_mulmul { |
|
65
|
|
|
|
|
|
|
my ($lhs, $rhs) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
croak "right hand side must be a scalar" if ref($rhs); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return bless { unit=>($lhs->{unit} ** $rhs) }, ref $lhs; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
# }}} |
|
72
|
|
|
|
|
|
|
# au_sqrt {{{ |
|
73
|
|
|
|
|
|
|
sub au_sqrt { |
|
74
|
|
|
|
|
|
|
my ($lhs) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return bless { unit=>sqrt($lhs->{unit}) }, ref $lhs; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
# }}} |
|
79
|
|
|
|
|
|
|
# au_div {{{ |
|
80
|
|
|
|
|
|
|
sub au_div { |
|
81
|
|
|
|
|
|
|
my ($lhs, $rhs) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return bless { unit=>($lhs->{unit} / $rhs->{unit}) }, ref $lhs; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
# }}} |
|
86
|
|
|
|
|
|
|
# au_print {{{ |
|
87
|
|
|
|
|
|
|
sub au_print { |
|
88
|
|
|
|
|
|
|
my $this = shift; |
|
89
|
|
|
|
|
|
|
my $a = $this->{unit}; |
|
90
|
|
|
|
|
|
|
$a =~ s/\$xx//g; |
|
91
|
|
|
|
|
|
|
$a =~ s/\*\*/\^/g; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return $a; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
# }}} |
|
96
|
|
|
|
|
|
|
# au_eq {{{ |
|
97
|
|
|
|
|
|
|
sub au_eq { |
|
98
|
|
|
|
|
|
|
my ($lhs, $rhs) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return $lhs->au_print eq $rhs->au_print; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
# }}} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
"this file is true" |