blib/lib/Bot/MetaSyntactic.pm

filter: Statementstmt 46.0% 29 / 63 Branchbran 4.5% 1 / 22 Conditioncond 10.0% 1 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 80.0% 8 / 10 Podpod 100% 3 / 3 totaltotal 37.1% 42 / 113 CC 15 SCAR 46.0
CC
15
Cov
33%
said
182.0
init
3.8
help
2.0
CRAP 99.4
↑ Summary
1 package Bot::MetaSyntactic;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Acme::MetaSyntactic;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Bot::BasicBot;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use I18N::LangTags qw(extract_language_tags);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶{ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 $VERSION = '0.0301';
11 3 @ISA = qw(Bot::BasicBot);
12 }
13  
14 =head1 NAME
15  
16 Bot::MetaSyntactic - IRC frontend to Acme::MetaSyntactic
17  
18 =head1 VERSION
19  
20 Version 0.03
21  
22 =head1 SYNOPSIS
23  
24 use Bot::MetaSyntactic;
25  
26 Bot::MetaSyntactic->new(
27 nick => 'meta',
28 name => 'Acme::MetaSyntactic IRC frontend',
29 server => 'irc.perl.org',
30 channels => ['#randomchan']
31 )->run
32  
33 =head1 DESCRIPTION
34  
35 This module provides the glue for providing an IRC interface to
36 the module C<Acme::MetaSyntactic>.
37  
38 =head1 FUNCTIONS
39  
40 =over 4
41  
42 =item init()
43  
44 Initializes private data.
45  
46 =cut
47  
48 1 ▶sub init {
Subroutine init: called CC=3 SCAR=13.5
Pod documented
49 1 my $self = shift;
50  
51 $self->{meta} = {
52 1 obj => undef,
53 limit => 100,
54 wrap => 256,
55 };
56
57 1 $Text::Wrap::columns = $self->{meta}{wrap};
58  
59 1 ▶ $self->{meta}{obj} = Acme::MetaSyntactic->new
Branch: 1 branch
BranchTrueFalseTotal
$self->{"meta"}{"obj"} = "Acme::MetaSyntactic"->new or carp("fatal: Can't create new Acme::MetaSyntactic object") and return undef 1 0 1
Condition20%1/5
($self->{'meta'}{'obj'} = 'Acme::MetaSyntactic'->new) || carp(q[fatal: Can't create new Acme::MetaSyntactic object]) && (return undef)
l!l&&r!l&&!r
100
carp("fatal: Can't create new Acme::MetaSyntactic object") and return undef
!ll
00
MC/DC0%0/2
($self->{'meta'}{'obj'} = 'Acme::MetaSyntactic'->new) || carp(q[fatal: Can't create new Acme::MetaSyntactic object]) && (return undef)
($self->{'meta'}{'obj'} = 'Acme::MetaSyntactic'->new) carp("fatal: Can't create new Acme::MetaSyntactic object")
Truth table33%1/3
A || B
A= ($self->{'meta'}{'obj'} = 'Acme::MetaSyntactic'->new)B= carp("fatal: Can't create new Acme::MetaSyntactic object")
ABresult
1X1
011
000
60 or carp "fatal: Can't create new Acme::MetaSyntactic object"
61 and return undef;
62 }
63  
64 =item said()
65  
66 Main function for interacting with the bot object.
67 It follows the C<Bot::BasicBot> API and expect an hashref as argument.
68 See L<"COMMANDS"> for more information on recognized commands.
69  
70 =cut
71  
72 0 ▶sub said {
Subroutine said: not called CC=13 SCAR=52.0
Pod documented
73 0 my $self = shift;
74 0 my $args = shift;
75 0 my($number,$theme);
76  
77 # don't do anything unless directly addressed
78 0 ▶ return undef unless $args->{address} eq $self->nick or $args->{channel} eq 'msg';
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"address"} eq $self->nick or $args->{"channel"} eq "msg" 0 0 0
Condition0%0/3
$args->{"address"} eq $self->nick or $args->{"channel"} eq "msg"
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"address"} eq $self->nick or $args->{"channel"} eq "msg"
$args->{"address"} eq $self->nick $args->{"channel"} eq "msg"
Truth table0%0/3
A or B
A= $args->{"address"} eq $self->nickB= $args->{"channel"} eq "msg"
ABresult
1X1
011
000
79 0 ▶ return if $self->ignore_nick($args->{who});
Branch: 1 branch
BranchTrueFalseTotal
if $self->ignore_nick($args->{"who"}) 0 0 0
80  
81 # ignore karma
82 0 ▶ return if index($args->{body}, '++') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($args->{"body"}, "++") == 0 0 0 0
83 0 ▶ return if index($args->{body}, '--') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($args->{"body"}, "--") == 0 0 0 0
84  
85 0 my @themes = Acme::MetaSyntactic->themes;
86  
87 {
88 0 $args->{body} =~ s/\b(\d+)\b//;
89 0 ▶ $number = defined($1) ? $1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 0 0 0
90 0 ▶ $number = $self->{meta}{limit} if $number > $self->{meta}{limit};
Branch: 1 branch
BranchTrueFalseTotal
if $number > $self->{"meta"}{"limit"} 0 0 0
91 }
92  
93 {
94 0 $args->{body} =~ s/(\w+)//;
95 0 ▶ $theme = $1 || 'any';
Condition0%0/2
$1 || 'any'
l!l
00
MC/DC0%0/1
$1 || 'any'
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
96 }
97  
98 0 ▶ if ($theme eq 'version') {
Branch: 1 branch
BranchTrueFalseTotal
if ($theme eq "version") 0 0 0
99 $args->{body} = sprintf "%s IRC bot, using %s", $self->nick,
100 0 join ', ', map { $_ . ' ' . $_->VERSION } qw(
101 Acme::MetaSyntactic Bot::BasicBot Bot::MetaSyntactic
102 POE POE::Component::IRC
103 );
104 0 $self->say($args);
105 0 return undef;
106 }
107  
108 0 ▶ if ($theme eq 'themes') {
Branch: 1 branch
BranchTrueFalseTotal
if ($theme eq "themes") 0 0 0
109 0 $args->{body} = "Available themes: @themes";
110 0 $self->say($args);
111 0 return undef;
112 }
113
114 0 ▶ unless (Acme::MetaSyntactic->has_theme($theme)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Acme::MetaSyntactic"->has_theme($theme)) 0 0 0
115 0 $args->{body} = "No such theme: $theme";
116 0 $self->say($args);
117 0 return undef;
118 }
119  
120 0 my @words = $self->{meta}{obj}->name($theme => $number);
121 0 ▶ @words = @words[0..$self->{meta}{limit}] if @words > $self->{meta}{limit};
Branch: 1 branch
BranchTrueFalseTotal
if @words > $self->{"meta"}{"limit"} 0 0 0
122  
123 0 $args->{body} = join ' ', wrap('', '', @words);
124 0 $self->say($args);
125  
126 return undef
127 0 }
128  
129 =item help()
130  
131 Prints usage.
132  
133 =cut
134  
135 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
136 0 return "usage: meta [theme] [number]\n".
137 " use theme name 'themes' to print all available themes"
138 }
139  
140 =back
141  
142 =head1 COMMANDS
143  
144 Syntax (assuming the name of the bot is C<meta>):
145  
146 meta [theme] [number]
147 meta themes
148  
149 Called with no argument, print this number of random words from a random theme.
150  
151 Called with a theme name, print this number of random words from this theme.
152  
153 Called with C<themes>, print all available themes.
154  
155  
156 =head1 DIAGNOSTICS
157  
158 =over 4
159  
160 =item Can't create new %s object
161  
162 B<(F)> Occurs in C<init()>. As the message says, we were unable to create
163 a new object of the given class.
164  
165 =back
166  
167 =head1 SEE ALSO
168  
169 L<Acme::MetaSyntactic>, L<Bot::BasicBot>
170  
171 =head1 AUTHOR
172  
173 SE<eacute>bastien Aperghis-Tramoni, E<lt>sebastien@aperghis.netE<gt>
174  
175 =head1 BUGS
176  
177 Please report any bugs or feature requests to
178 C<bug-bot-metasyntactic@rt.cpan.org>, or through the web interface at
179 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Bot-MetaSyntactic>.
180 I will be notified, and then you'll automatically be notified
181 of progress on your bug as I make changes.
182  
183 =head1 COPYRIGHT & LICENSE
184  
185 Copyright 2005 SE<eacute>bastien Aperghis-Tramoni, All Rights Reserved.
186  
187 This program is free software; you can redistribute it and/or modify it
188 under the same terms as Perl itself.
189  
190 =cut
191  
192 3 1; # End of Bot::MetaSyntactic
↑ Summary