line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::IRC::Convert; |
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::IRC convert units of amounts |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2821
|
use 5.014; |
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
21
|
use exact -noutf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1197
|
use Math::Units 'convert'; |
|
1
|
|
|
|
|
4399
|
|
|
1
|
|
|
|
|
435
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.38'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
1
|
|
|
1
|
0
|
6395
|
my ($bot) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$bot->hook( |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
command => 'PRIVMSG', |
17
|
|
|
|
|
|
|
text => qr/^(?<amount>[\d,\.]+)\s+(?<in_unit>\S+)\s+(?:in|as|to|into)\s+(?<out_unit>\S+)/, |
18
|
|
|
|
|
|
|
}, |
19
|
|
|
|
|
|
|
sub { |
20
|
1
|
|
|
1
|
|
1746
|
my ( $bot, $in, $m ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
4
|
( my $amount = $m->{amount} ) =~ s/,//g; |
23
|
1
|
|
|
|
|
3
|
my $value; |
24
|
1
|
|
|
|
|
1
|
eval { $value = convert( $amount, $m->{in_unit}, $m->{out_unit} ) }; |
|
1
|
|
|
|
|
6
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
50
|
|
|
|
17644
|
$bot->reply("$m->{amount} $m->{in_unit} is $value $m->{out_unit}") if ($value); |
27
|
|
|
|
|
|
|
}, |
28
|
1
|
|
|
|
|
26
|
); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
16
|
$bot->helps( convert => 'Convert units of value. Usage: <amount> <input unit> as <output unit>.' ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding UTF-8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Bot::IRC::Convert - Bot::IRC convert units of amounts |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 VERSION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
version 1.38 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use Bot::IRC; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Bot::IRC->new( |
54
|
|
|
|
|
|
|
connect => { server => 'irc.perl.org' }, |
55
|
|
|
|
|
|
|
plugins => ['Convert'], |
56
|
|
|
|
|
|
|
)->run; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This L<Bot::IRC> plugin allows the bot to convert various values of units. |
61
|
|
|
|
|
|
|
Unit types must match, which is to say you can't convert length to volume. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 SEE ALSO |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
L<Bot::IRC> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=for Pod::Coverage init |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Gryphon Shafer <gryphon@cpan.org> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This software is Copyright (c) 2016-2021 by Gryphon Shafer. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is free software, licensed under: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |