blib/lib/Bot/BasicBot/Pluggable/Module/MetaSyntactic.pm

filter: Statementstmt 100% 74 / 74 Branchbran 91.6% 44 / 48 Conditioncond 82.8% 29 / 35 MC/DCmcdc 52.3% 11 / 21 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 89.5% 171 / 191 CC 37 SCAR 33.1
CC
37
Cov
94%
told
35.5
_load_theme
3.0
BEGIN
1.0
CRAP 27.4
↑ Summary
1 package Bot::BasicBot::Pluggable::Module::MetaSyntactic;
2 {
3 2 $Bot::BasicBot::Pluggable::Module::MetaSyntactic::VERSION = '1.004';
4 }
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Acme::MetaSyntactic ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our @ISA = qw(Bot::BasicBot::Pluggable::Module);
14  
15 2 ▶my $META = Acme::MetaSyntactic->new()
Branch: 1 branch
BranchTrueFalseTotal
my $META = "Acme::MetaSyntactic"->new or carp("fatal: Can't create new Acme::MetaSyntactic object") 2 0 2
16 or carp "fatal: Can't create new Acme::MetaSyntactic object";
17  
18 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
19 1 my $self = shift;
20  
21 $self->{meta} = {
22 1 limit => 100,
23 wrap => 256,
24 };
25  
26 1 $Text::Wrap::columns = $self->{meta}{wrap};
27 }
28  
29 29 ▶sub told {
Subroutine told: called CC=35 SCAR=35.7
Pod documented
30 29 my ( $self, $mess ) = @_;
31 29 my $bot = $self->bot();
32  
33 # we must be directly addressed
34 return
35 if !( ( defined $mess->{address}
36 && $mess->{address} eq $bot->nick()
37 )
38 29 ▶ || $mess->{channel} eq 'msg'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg" 2 27 29
Condition100%6/6
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg"
l!l&&r!l&&!r
2252
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick
!ll&&!rl&&r
2252
MC/DC33%1/3
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg"
defined $mess->{"address"} $mess->{"address"} eq $bot->nick $mess->{"channel"} eq "msg"
Truth table60%3/5
A and B or C
A= defined $mess->{"address"}B= $mess->{"address"} eq $bot->nickC= $mess->{"channel"} eq "msg"
ABCresult
11X1
0X11
1011
0X00
1000
39 );
40  
41 # ignore people we ignore
42 27 ▶ return if $bot->ignore_nick( $mess->{who} );
Branch: 1 branch
BranchTrueFalseTotal
if $bot->ignore_nick($mess->{"who"}) 0 27 27
43  
44 # only answer to our command (which can be our name too)
45 27 ▶ my $src = $bot->nick() eq 'meta' ? 'raw_body' : 'body';
Branch: 1 branch
BranchTrueFalseTotal
$bot->nick eq 'meta' ? : 1 26 27
46 27 ▶ return if $mess->{$src} !~ /^\s*meta(.*)/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $mess->{$src} =~ /^\s*meta(.*)/i 2 25 27
47  
48 # ignore the noise
49 25 ( my $command = "$1" ) =~ s/^\W*//;
50  
51 # pick up the commands
52 25 ( $command, my @args ) = split /\s+/, $command;
53 25 ▶ return if !$command || !length $command;
Branch: 1 branch
BranchTrueFalseTotal
unless $command and length $command 1 24 25
Condition66%2/3
$command and length $command
!ll&&!rl&&r
1024
MC/DC50%1/2
$command and length $command
$command length $command
Truth table66%2/3
A and B
A= $commandB= length $command
ABresult
0X0
100
111
54  
55 # it's a theme
56 24 ▶ if ( $command =~ /^[-\w\/]+$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($command =~ m[^[-\w/]+$]) { } 20 4 24
elsif ($command eq 'themes?') { } 1 3 4
elsif ($command eq 'categories?') { } 3 0 3
57 20 my ( $theme, $category ) = split m'/', $command, 2;
58 20 ▶ $self->{meta}{theme}{$command} //= _load_theme($theme, $category);
Condition66%2/3
$self->{"meta"}{"theme"}{$command} //= _load_theme($theme, $category)
l!l&&r!l&&!r
1550
MC/DC0%0/2
$self->{"meta"}{"theme"}{$command} //= _load_theme($theme, $category)
$self->{"meta"}{"theme"}{$command} _load_theme($theme, $category)
Truth table66%2/3
A //= B
A= $self->{"meta"}{"theme"}{$command}B= _load_theme($theme, $category)
ABresult
1X1
011
000
59 20 ▶ return "No such theme: $theme"
Branch: 1 branch
BranchTrueFalseTotal
unless $META->has_theme($theme) 1 19 20
60 if !$META->has_theme($theme);
61 19 ▶ if ( $category && $self->{meta}{theme}{$command}
Branch: 1 branch
BranchTrueFalseTotal
if ($category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList") and not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)) 1 18 19
Condition83%5/6
$category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList") and not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
!ll&&!rl&&r
1531
$category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList")
!ll&&!rl&&r
1504
MC/DC66%2/3
$category and $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList") and not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
$category $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList") not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
Truth table75%3/4
A and B and not(C)
A= $categoryB= $self->{"meta"}{"theme"}{$command}->isa("Acme::MetaSyntactic::MultiList")C= not grep({$_ eq $category;} $self->{"meta"}{"theme"}{$command}->categories)
ABCresult
0XX0
10X0
1100
1111
62 ->isa('Acme::MetaSyntactic::MultiList')
63 12 && !grep { $_ eq $category }
64 $self->{meta}{theme}{$command}->categories )
65 {
66 1 delete $self->{meta}{theme}{$command};
67 1 return "No such theme/category: $theme/$category";
68 }
69  
70 # compute the list of items
71 18 my ( $num, $re );
72 18 for my $arg (@args) {
73 22 ▶ if ( $arg =~ /^[0-9]+$/ ) { $num //= $arg; }
Branch: 2 branches
BranchTrueFalseTotal
if ($arg =~ /^[0-9]+$/) { } 12 10 22
elsif ($arg =~ m[^/([^\/]*)/$]) { } 9 1 10
Condition33%1/3
$num //= $arg
l!l&&r!l&&!r
0120
MC/DC0%0/2
$num //= $arg
$num $arg
Truth table33%1/3
A //= B
A= $numB= $arg
ABresult
1X1
011
000
74 elsif ( $arg =~ m{^/([^\/]*)/$} ) {
75 9 $re = eval {qr/$1/}
76 9 ▶ or do { ( my $err = $@ ) =~ s/ at .*//s; return $err; }
Branch: 1 branch
BranchTrueFalseTotal
$re = eval { do { qr/$1/ } } or do { (my $err = $@) =~ s/ at .*//s; return $err } 8 1 9
77 }
78 1 else {return} # can't parse this argument
79 }
80  
81 # enforce the limit if explicitely asked for more
82 16 ▶ $num //= 1;
Condition100%2/2
$num //= 1
l!l
124
MC/DC100%1/1
$num //= 1
$num
Truth table100%2/2
A
A= $num
Aresult
11
00
83 16 ▶ $num = $self->{meta}{limit} if $num > $self->{meta}{limit};
Branch: 1 branch
BranchTrueFalseTotal
if $num > $self->{"meta"}{"limit"} 1 15 16
84  
85 16 my $meta = $self->{meta}{theme}{$command};
86 16 ▶ my @items = $meta->name( $re ? 0 : $num );
Branch: 1 branch
BranchTrueFalseTotal
$re ? : 8 8 16
87 16 ▶ if ($re) { # NOTE: the extra loop is never run if $num == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($re) 8 8 16
88 8 @items = grep /$re/, @items;
89 8 ▶ splice @items, $num if $num && @items > $num;
Branch: 1 branch
BranchTrueFalseTotal
if $num and @items > $num 2 6 8
Condition100%3/3
$num and @items > $num
!ll&&!rl&&r
332
MC/DC100%2/2
$num and @items > $num
$num @items > $num
Truth table100%3/3
A and B
A= $numB= @items > $num
ABresult
0X0
100
111
90 8 ▶ push @items, grep /$re/, $meta->name(0)
Branch: 1 branch
BranchTrueFalseTotal
@items and @items < $num and do { push @items, grep(/$re/, $meta->name(0)) } 1 8 9
Condition100%3/3
@items and @items < $num
!ll&&!rl&&r
351
MC/DC100%2/2
@items and @items < $num
@items @items < $num
Truth table100%3/3
A and B
A= @itemsB= @items < $num
ABresult
0X0
100
111
91 while @items && @items < $num;
92 }
93 splice @items, $self->{meta}{limit} # enforce the limit
94 16 ▶ if @items > $self->{meta}{limit};
Branch: 1 branch
BranchTrueFalseTotal
if @items > $self->{"meta"}{"limit"} 1 15 16
95 16 return join ' ', @items;
96 }
97  
98 # it's a command
99 elsif ( $command eq 'themes?' ) {
100 1 my @themes = $META->themes();
101 1 return join ' ', scalar @themes, 'themes available:', @themes;
102 }
103 elsif ( $command eq 'categories?' ) {
104 3 ▶ return if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 3 3
105 3 my $theme = shift @args;
106 3 ▶ $self->{meta}{theme}{$theme} //= _load_theme($theme);
Condition66%2/3
$self->{"meta"}{"theme"}{$theme} //= _load_theme($theme)
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->{"meta"}{"theme"}{$theme} //= _load_theme($theme)
$self->{"meta"}{"theme"}{$theme} _load_theme($theme)
Truth table66%2/3
A //= B
A= $self->{"meta"}{"theme"}{$theme}B= _load_theme($theme)
ABresult
1X1
011
000
107 3 ▶ return "No such theme: $theme"
Branch: 1 branch
BranchTrueFalseTotal
unless $META->has_theme($theme) 1 2 3
108 if !$META->has_theme($theme);
109 return "Theme $theme does not have any categories"
110 2 ▶ if !$self->{meta}{theme}{$theme}
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"meta"}{"theme"}{$theme}->isa("Acme::MetaSyntactic::MultiList") 1 1 2
111 ->isa('Acme::MetaSyntactic::MultiList');
112 return join ' ', "Categories for $theme:",
113 1 sort $self->{meta}{theme}{$theme}->categories;
114 }
115 }
116  
117 6 ▶sub _load_theme {
Subroutine _load_theme: called CC=3 SCAR=11.0
118 6 my ($theme, $category) = @_;
119 6 my $module = "Acme::MetaSyntactic::$theme";
120 6 ▶ return eval "require $module" || $META->has_theme($theme)
Branch: 1 branch
BranchTrueFalseTotal
eval "require $module" || $META->has_theme($theme) ? : 5 1 6
Condition100%3/3
eval "require $module" or $META->has_theme($theme)
l!l&&r!l&&!r
411
MC/DC100%2/2
eval "require $module" or $META->has_theme($theme)
eval "require $module" $META->has_theme($theme)
Truth table100%3/3
A or B
A= eval "require $module"B= $META->has_theme($theme)
ABresult
1X1
011
000
121 ? $module->new( ( category => $category ) x !!$category )
122 : '';
123 }
124  
125 1 ▶sub help {'meta theme [count]'}
Subroutine help: called CC=1 SCAR=0.0
Pod documented
126  
127 2 1;
128  
129 # ABSTRACT: IRC frontend to Acme::MetaSyntactic
130  
131  
132 __END__
↑ Summary