| 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
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $self->set("user_shorten_service", 'Metamark') unless defined($self->get("user_shorten_service")); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $self->{"_old_service"} or $self->{"_old_service"} ne $service
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return if $body =~ /phobos.apple.com/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return unless $body =~ m!(http://\S+)!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return unless length($1) > $self->get("user_max_length"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $short = makeashorterlink($long) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return unless length($short) < length($long); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return unless $short; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->{Bot}->reply($mess, "urgh. long url. Try $short"); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||