line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bot::IRC::Math; |
2
|
|
|
|
|
|
|
# ABSTRACT: Bot::IRC evaluate math expressions and return results |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2364
|
use 5.014; |
|
1
|
|
|
|
|
3
|
|
5
|
1
|
|
|
1
|
|
19
|
use exact; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1491
|
use Math::Expression; |
|
1
|
|
|
|
|
5930
|
|
|
1
|
|
|
|
|
402
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.38'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
1
|
|
|
1
|
0
|
7153
|
my ($bot) = @_; |
13
|
1
|
|
|
0
|
|
16
|
my $expr = Math::Expression->new( PrintErrFunc => sub {} ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$bot->hook( |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
command => 'PRIVMSG', |
18
|
|
|
|
|
|
|
text => qr/^[\d\s\+\-\/\*\%\^\(\)]+$/, |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
sub { |
21
|
0
|
|
|
0
|
|
0
|
my ( $bot, $in ) = @_; |
22
|
0
|
|
|
|
|
0
|
my $value = $expr->EvalToScalar( $expr->Parse( $in->{text} ) ); |
23
|
0
|
|
|
|
|
0
|
( my $clean_text = $in->{text} ) =~ s/\s+//g; |
24
|
0
|
0
|
0
|
|
|
0
|
$bot->reply($value) if ( $value and $value ne $clean_text ); |
25
|
|
|
|
|
|
|
}, |
26
|
1
|
|
|
|
|
90
|
); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
22
|
$bot->helps( math => 'Evaluate math expressions. Usage: <math expression>.' ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__END__ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=encoding UTF-8 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Bot::IRC::Math - Bot::IRC evaluate math expressions and return results |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 VERSION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
version 1.38 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Bot::IRC; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Bot::IRC->new( |
52
|
|
|
|
|
|
|
connect => { server => 'irc.perl.org' }, |
53
|
|
|
|
|
|
|
plugins => ['Math'], |
54
|
|
|
|
|
|
|
)->run; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This L<Bot::IRC> plugin gives the bot the capability to evaluate math |
59
|
|
|
|
|
|
|
expressions and return the results. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
See L<Math::Expression> for details. Message text is evaluated with C<Parse> |
62
|
|
|
|
|
|
|
and C<EvalToScalar> from L<Math::Expression>. If there's a value generated, the |
63
|
|
|
|
|
|
|
bot replies with the value. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 SEE ALSO |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L<Bot::IRC> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=for Pod::Coverage init |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 AUTHOR |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Gryphon Shafer <gryphon@cpan.org> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This software is Copyright (c) 2016-2021 by Gryphon Shafer. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is free software, licensed under: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |