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

filter: Statementstmt 89.1% 41 / 46 Branchbran 56.2% 9 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 81.2% 65 / 80 SCAR 24.8
CC
11
Cov
80%
admin
14.5
help
2.0
BEGIN
1.0
CRAP 12.0
« blib/lib/Bot/BasicBot/Pluggable/Module/DNS.pm ↑ Summary Build »
1 package Bot::BasicBot::Pluggable::Module::Title;
2 1 $Bot::BasicBot::Pluggable::Module::Title::VERSION = '1.20';
3 1 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Text::Unidecode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use URI::Title qw(title);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use URI::Find::Simple qw(list_uris);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub help {
13 0 ▶ return "Speaks the title of URLs mentioned.";
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
14 }
15  
16 sub init {
17 1 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod documented
18 1 $self->config(
19 {
20 user_asciify => 1,
21 user_ignore_re => '',
22 user_be_rude => 0,
23 }
24 );
25 }
26  
27 sub admin {
28  
29 # do this in admin so we always get a chance to see titles
30 3 ▶ my ( $self, $mess ) = @_;
Subroutine admin: called CC=11 SCAR=26.8
Pod documented
31  
32 # If the message was from the bot (for e.g. another module announcing the
33 # title of an URL we just said, etc), go no further, to avoid loops
34 3 ▶ return if $mess->{who} eq $self->bot->nick;
Branch: 1 branch
BranchTrueFalseTotal
if $mess->{"who"} eq $self->bot->nick 0 3 3
35  
36 3 my $ignore_regexp = $self->get('user_ignore_re');
37  
38 3 my $reply = "";
39 3 for ( list_uris( $mess->{body} ) ) {
40 3 ▶ next if $ignore_regexp && /$ignore_regexp/;
Branch: 1 branch
BranchTrueFalseTotal
if $ignore_regexp and /$ignore_regexp/ 1 2 3
Condition66%2/3
$ignore_regexp and /$ignore_regexp/
!ll&&!rl&&r
201
MC/DC50%1/2
$ignore_regexp and /$ignore_regexp/
$ignore_regexp /$ignore_regexp/
Truth table66%2/3
A and B
A= $ignore_regexpB= /$ignore_regexp/
ABresult
0X0
100
111
41 2 my $uri = URI->new($_);
42 2 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 2 2
43 2 ▶ if ( $uri->scheme eq "file" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->scheme eq "file") 0 2 2
44 0 ▶ next unless $self->get("user_be_rude");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("user_be_rude") 0 0 0
45 0 my $who = $mess->{who};
46 0 $self->reply( $mess, "Nice try $who, you tosser" );
47 0 return;
48 }
49  
50 2 my $title = title("$_");
51 2 ▶ next unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 0 2 2
52 2 ▶ $title = unidecode($title) if $self->get("user_asciify");
Branch: 1 branch
BranchTrueFalseTotal
if $self->get("user_asciify") 2 0 2
53 2 $reply .= "[ $title ] ";
54 }
55  
56 3 ▶ if ($reply) { $self->reply( $mess, $reply ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($reply) 2 1 3
57  
58 3 return; # Title.pm is passive, and doesn't intercept things.
59 }
60  
61 1 1;
62  
63 __END__
64  
65 =head1 NAME
66  
67 Bot::BasicBot::Pluggable::Module::Title - speaks the title of URLs mentioned
68  
69 =head1 VERSION
70  
71 version 1.20
72  
73 =head1 IRC USAGE
74  
75 None. If the module is loaded, the bot will speak the titles of all URLs mentioned.
76  
77 =head1 VARS
78  
79 =over 4
80  
81 =item asciify
82  
83 Defaults to 1; whether or not we should convert all titles to ascii from Unicode
84  
85 =item ignore_re
86  
87 If set to a nonempty string, ignore URLs matching this re
88  
89 =back
90  
91 =head1 REQUIREMENTS
92  
93 L<URI::Title>
94  
95 L<URI::Find::Simple>
96  
97 =head1 AUTHOR
98  
99 Mario Domgoergen <mdom@cpan.org>
100  
101 This program is free software; you can redistribute it
102 and/or modify it under the same terms as Perl itself.
« blib/lib/Bot/BasicBot/Pluggable/Module/DNS.pm ↑ Summary Build »