line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
## Telegram API - ~/lib/Net/API/Telegram/Number.pm |
4
|
|
|
|
|
|
|
## Version 0.1 |
5
|
|
|
|
|
|
|
## Copyright(c) 2019 Jacques Deguest |
6
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
7
|
|
|
|
|
|
|
## Created 2019/06/02 |
8
|
|
|
|
|
|
|
## Modified 2019/06/02 |
9
|
|
|
|
|
|
|
## All rights reserved |
10
|
|
|
|
|
|
|
## |
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
package Net::API::Telegram::Number; |
15
|
|
|
|
|
|
|
BEGIN |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
18
|
1
|
|
|
1
|
|
6
|
use parent qw( Module::Generic ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
19
|
1
|
|
|
1
|
|
57
|
use Number::Format; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
20
|
1
|
|
|
1
|
|
653
|
our( $VERSION ) = '0.1'; |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use overload ( |
24
|
|
|
|
|
|
|
'""' => sub |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
0
|
|
0
|
my $self = shift( @_ ); |
27
|
0
|
|
|
|
|
0
|
return( $self->{ '_number' } ); |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
'-' => sub |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
32
|
0
|
|
|
|
|
0
|
my $result = $self->{ '_number' } - $other; |
33
|
0
|
0
|
|
|
|
0
|
$result = -$result if( $swap ); |
34
|
0
|
|
|
|
|
0
|
return( $result ); |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
'+' => sub |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
39
|
0
|
|
|
|
|
0
|
my $result = $self->{ '_number' } + $other; |
40
|
0
|
|
|
|
|
0
|
return( $result ); |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
'*' => sub |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
45
|
0
|
|
|
|
|
0
|
my $result = $self->{ '_number' } * $other; |
46
|
0
|
|
|
|
|
0
|
return( $result ); |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
'/' => sub |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
51
|
0
|
0
|
|
|
|
0
|
if( $swap ) |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
0
|
return( $other / $self->{ '_number' } ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
0
|
return( $self->{ '_number' } / $other ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
'<' => sub |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
63
|
0
|
0
|
|
|
|
0
|
return( $swap ? $other < $self->{ '_number' } : $self->{ '_number' } < $other ); |
64
|
|
|
|
|
|
|
}, |
65
|
|
|
|
|
|
|
'<=' => sub |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
68
|
0
|
0
|
|
|
|
0
|
return( $swap ? $other <= $self->{ '_number' } : $self->{ '_number' } <= $other ); |
69
|
|
|
|
|
|
|
}, |
70
|
|
|
|
|
|
|
'>' => sub |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
73
|
0
|
0
|
|
|
|
0
|
return( $swap ? $other > $self->{ '_number' } : $self->{ '_number' } > $other ); |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
'>=' => sub |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
78
|
0
|
0
|
|
|
|
0
|
return( $swap ? $other >= $self->{ '_number' } : $self->{ '_number' } >= $other ); |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
'<=>' => sub |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
83
|
0
|
0
|
|
|
|
0
|
return( $swap ? $other <=> $self->{ '_number' } : $self->{ '_number' } <=> $other ); |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
'==' => sub |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
88
|
0
|
|
|
|
|
0
|
return( $self->{ '_number' } == $other ); |
89
|
|
|
|
|
|
|
}, |
90
|
|
|
|
|
|
|
'!=' => sub |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
93
|
0
|
|
|
|
|
0
|
return( $self->{ '_number' } == $other ); |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
'eq' => sub |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
98
|
0
|
|
|
|
|
0
|
return( $self->{ '_number' } eq $other ); |
99
|
|
|
|
|
|
|
}, |
100
|
|
|
|
|
|
|
'ne' => sub |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
0
|
|
0
|
my( $self, $other, $swap ) = @_; |
103
|
0
|
|
|
|
|
0
|
return( $self->{ '_number' } ne $other ); |
104
|
|
|
|
|
|
|
} |
105
|
1
|
|
|
1
|
|
8
|
); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub init |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift( @_ ); |
110
|
0
|
|
|
|
|
|
my $num = shift( @_ ); |
111
|
0
|
|
|
|
|
|
$self->SUPER::init; |
112
|
0
|
|
|
|
|
|
$self->{ '_fmt' } = Number::Format->new( |
113
|
|
|
|
|
|
|
-thousands_sep => ',', |
114
|
|
|
|
|
|
|
-decimal_point => '.', |
115
|
|
|
|
|
|
|
-int_curr_symbol => 'Â¥', |
116
|
|
|
|
|
|
|
); |
117
|
0
|
|
|
|
|
|
$self->{ '_number' } = $num; |
118
|
0
|
|
|
|
|
|
return( $self ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
0
|
|
sub as_string { return( shift->{ '_number' } ) } |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub format |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
0
|
0
|
|
my $self = shift( @_ ); |
126
|
1
|
|
|
1
|
|
418
|
no overloading; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
127
|
0
|
|
|
|
|
|
my $num = $self->{ '_number' }; |
128
|
|
|
|
|
|
|
## If value provided was undefined, we leave it undefined, otherwise we would be at risk of returning 0, and 0 is very different from undefined |
129
|
0
|
0
|
|
|
|
|
return( $num ) if( !defined( $num ) ); |
130
|
0
|
|
|
|
|
|
my $fmt = $self->{ '_fmt' }; |
131
|
0
|
|
|
|
|
|
return( $fmt->format_number( $num, @_ ) ); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub format_money |
135
|
|
|
|
|
|
|
{ |
136
|
0
|
|
|
0
|
0
|
|
my $self = shift( @_ ); |
137
|
1
|
|
|
1
|
|
9
|
no overloading; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
104
|
|
138
|
0
|
|
|
|
|
|
my $num = $self->{ '_number' }; |
139
|
|
|
|
|
|
|
## See comment in format() method |
140
|
0
|
0
|
|
|
|
|
return( $num ) if( !defined( $num ) ); |
141
|
0
|
|
|
|
|
|
my $fmt = $self->{ '_fmt' }; |
142
|
0
|
|
|
|
|
|
return( $fmt->format_price( $num, @_ ) ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |
148
|
|
|
|
|
|
|
|