File Coverage

blib/lib/Bot/IRC/Convert.pm
Criterion Covered Total %
statement 17 17 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 23 25 92.0


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