| 1 | package Bot::IRC::Math; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Bot::IRC evaluate math expressions and return results | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use exact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Math::Expression; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '1.49'; # VERSION | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=2.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 1 | my ($bot) = @_; | |||||||||||||||||||||||||||
| 13 | 1 | ▶ | my $expr = Math::Expression->new( PrintErrFunc => sub {} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | $bot->hook( | ||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||
| 17 | command => 'PRIVMSG', | ||||||||||||||||||||||||||||
| 18 | text => qr/^[\d\s\+\-\/\*\%\^\(\)]+$/, | ||||||||||||||||||||||||||||
| 19 | }, | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 21 | 0 | my ( $bot, $in ) = @_; | |||||||||||||||||||||||||||
| 22 | 0 | my $value = $expr->EvalToScalar( $expr->Parse( $in->{text} ) ); | |||||||||||||||||||||||||||
| 23 | 0 | ( my $clean_text = $in->{text} ) =~ s/\s+//g; | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | $bot->reply($value) if ( $value and $value ne $clean_text ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$value and $value ne $clean_text
MC/DC0%0/2
$value and $value ne $clean_text
$value
$value ne $clean_text
Truth table0%0/3
A and B
A= $valueB= $value ne $clean_text
| |||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | 1 | ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | $bot->helps( math => 'Evaluate math expressions. Usage: <math expression>.' ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | 1; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | __END__ | ||||||||||||||||||||||||||||