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
|
|
2699
|
use 5.014; |
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
7
|
use exact -noutf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1290
|
use Math::Units 'convert'; |
|
1
|
|
|
|
|
4285
|
|
|
1
|
|
|
|
|
386
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.40'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
1
|
|
|
1
|
0
|
6197
|
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
|
|
306
|
my ( $bot, $in, $m ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
5
|
( my $amount = $m->{amount} ) =~ s/,//g; |
23
|
1
|
|
|
|
|
2
|
my $value; |
24
|
1
|
|
|
|
|
2
|
eval { $value = convert( $amount, $m->{in_unit}, $m->{out_unit} ) }; |
|
1
|
|
|
|
|
4
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
50
|
|
|
|
18055
|
$bot->reply("$m->{amount} $m->{in_unit} is $value $m->{out_unit}") if ($value); |
27
|
|
|
|
|
|
|
}, |
28
|
1
|
|
|
|
|
26
|
); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
17
|
$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.40 |
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-2050 by Gryphon Shafer. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This is free software, licensed under: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |