LongURLs.pm

filter: Statementstmt 37.7% 17 / 45 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 28.7% 25 / 87 CC 15 SCAR 45.3
CC
15
Cov
23%
said
153.9
init
12.0
help
2.0
CRAP 92.9
« Maths.pm ↑ Summary Status.pm »
1 package Bot::BasicBot::Pluggable::Module::LongURLs;
2 1 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 require WWW::Shorten;
9  
10 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
11 0 my ($self, $mess) = @_;
12 0 return "I hate long URLs.";
13 }
14  
15 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
16 0 my $self = shift;
17 0 ▶ $self->set("user_max_length", 100) unless defined($self->get("user_max_length"));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->get("user_max_length") 0 0 0
18 0 ▶ $self->set("user_shorten_service", 'Metamark') unless defined($self->get("user_shorten_service"));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->get("user_shorten_service") 0 0 0
19 }
20  
21  
22 0 ▶sub said {
Subroutine said: not called CC=13 SCAR=50.4
Pod documented
23 0 my ($self, $mess, $pri) = @_;
24 0 ▶ return unless ($pri == 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $pri == 0 0 0 0
25  
26 0 my $service = $self->get("user_shorten_service");
27 0 ▶ if (!defined $self->{_old_service} || $self->{_old_service} ne $service)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"_old_service"} or $self->{"_old_service"} ne $service) 0 0 0
Condition0%0/3
not defined $self->{"_old_service"} or $self->{"_old_service"} ne $service
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->{"_old_service"} or $self->{"_old_service"} ne $service
not defined $self->{"_old_service"} $self->{"_old_service"} ne $service
Truth table0%0/3
not(A) or B
A= not defined $self->{"_old_service"}B= $self->{"_old_service"} ne $service
ABresult
1X1
011
000
28 {
29 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 0 eval { WWW::Shorten->import($service); };
31 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
32 0 $self->{Bot}->reply($mess, "Trying to use $service didn't work: $@");
33 0 $self->{_old_service} = undef;
34 0 return;
35 }
36 0 $self->{_old_service} = $service;
37 }
38  
39  
40 0 my $body = $mess->{body};
41
42 0 ▶ return unless defined $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 0 0
43 0 ▶ return if $body =~ /phobos.apple.com/;
Branch: 1 branch
BranchTrueFalseTotal
if $body =~ /phobos.apple.com/ 0 0 0
44 0 ▶ return unless $body =~ m!(http://\S+)!;
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ m[(http://\S+)] 0 0 0
45 0 ▶ return unless length($1) > $self->get("user_max_length");
Branch: 1 branch
BranchTrueFalseTotal
unless length $1 > $self->get("user_max_length") 0 0 0
46 0 my $long = $1;
47 0 my $short = $long;
48
49 0 ▶ unless ($short =~ s!a\d+.\w.akamai\w*.net/\w+/\w+/\w+/\w+/!!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($short =~ s[a\d+.\w.akamai\w*.net/\w+/\w+/\w+/\w+/][]) 0 0 0
50 0 ▶ $short = makeashorterlink($long) or return;
Branch: 1 branch
BranchTrueFalseTotal
$short = makeashorterlink($long) or return 0 0 0
51 }
52 0 ▶ return unless length($short) < length($long);
Branch: 1 branch
BranchTrueFalseTotal
unless length $short < length $long 0 0 0
53 0 ▶ return unless $short;
Branch: 1 branch
BranchTrueFalseTotal
unless $short 0 0 0
54
55 0 $self->{Bot}->reply($mess, "urgh. long url. Try $short");
56  
57 }
58  
59 1 1;
« Maths.pm ↑ Summary Status.pm »