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