IRC/Functions.pm

filter: Statementstmt 100% 30 / 30 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 83.9% 47 / 56 CC 9 SCAR 19.9
CC
9
Cov
88%
__ANON__
9.4
init
1.0
BEGIN
1.0
CRAP 7.3
« IRC/Store.pm ↑ Summary IRC/Greeting.pm »
1 package Bot::IRC::Functions;
2 # ABSTRACT: Bot::IRC add maybe helpful functions to the bot
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 our $VERSION = '1.49'; # VERSION
8  
9 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
10 1 my ($bot) = @_;
11  
12 1 my $alphabet = 'abcdefghijklmnopqrstuvwxyz';
13 1 my $start = uc($alphabet) . $alphabet;
14 1 my @alphabet = split( '', $alphabet );
15  
16 $bot->hook(
17 {
18 command => 'PRIVMSG',
19 text => qr/^(?<function>ord|chr|ascii|rot\d+|crypt)\s+(?<input>.+)/i,
20 },
21 4 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=22.4
22 4 my ( $bot, $in, $m ) = @_;
23  
24 4 my $function = lc( $m->{function} );
25 4 my $text = '';
26  
27 4 ▶ if ( $function eq 'ord' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($function eq 'ord') { } 1 3 4
elsif ($function eq 'chr' or $function eq 'ascii' and $m->{'input'} =~ /^\d+$/u) { } 1 2 3
elsif ($function =~ /rot(\d+)/u) { } 1 1 2
elsif ($function eq 'crypt') { } 1 0 1
28 $text =
29 "\"$m->{input}\" has a numerical value of " .
30 1 join( ' ', map { ord($_) } split( '', $m->{input} ) ) . '.';
31 }
32 ▶ elsif ( $function eq 'chr' or $function eq 'ascii' and $m->{input} =~ /^\d+$/ ) {
Condition50%3/6
$function eq "chr" or $function eq "ascii" and $m->{"input"} =~ /^\d+$/u
l!l&&r!l&&!r
102
$function eq "ascii" and $m->{"input"} =~ /^\d+$/u
!ll&&!rl&&r
200
MC/DC33%1/3
$function eq "chr" or $function eq "ascii" and $m->{"input"} =~ /^\d+$/u
$function eq "chr" $function eq "ascii" $m->{"input"} =~ /^\d+$/u
Truth table50%2/4
A or B and C
A= $function eq "chr"B= $function eq "ascii"C= $m->{"input"} =~ /^\d+$/u
ABCresult
1XX1
0111
00X0
0100
33 $text =
34 "$m->{input} has a character value of \"" .
35 1 chr( $m->{input} ) . '".';
36 }
37 elsif ( $function =~ /rot(\d+)/ ) {
38 1 my $rot = $1;
39 1 my @this_alphabet = @alphabet;
40 1 push( @this_alphabet, splice( @this_alphabet, 0, $rot ) );
41 1 my $end = uc( join( '', @this_alphabet ) ) . join( '', @this_alphabet );
42 1 ( $text = $m->{input} ) =~ tr/$start/$end/;
43 1 $text = "The ROT$rot of your input is \"$text\".";
44 }
45 elsif ( $function eq 'crypt' ) {
46 my $salt = ( $m->{input} =~ s/(\w+)\s+(\w{2})\s*$/$1/ )
47 ? $2
48 1 ▶ : join( '', map { $alphabet[ int( rand() * @alphabet ) ] } 0 .. 1 );
Branch: 1 branch
BranchTrueFalseTotal
$m->{'input'} =~ s/(\w+)\s+(\w{2})\s*$/$1/u ? : 0 1 1
49 1 $text = 'The crypt value of your input is "' . crypt( $m->{input}, $salt ) . '".';
50 }
51  
52 4 ▶ $bot->reply($text) if ($text);
Branch: 1 branch
BranchTrueFalseTotal
if $text 4 0 4
53 },
54 1 );
55  
56 1 $bot->helps( functions =>
57 'A set of maybe useful functions. ' .
58 'Usage: ord <character>; (chr|ascii) <number>; rot<number> <string>; crypt <string> [<salt>].'
59 );
60 }
61  
62 2 1;
63  
64 __END__
« IRC/Store.pm ↑ Summary IRC/Greeting.pm »