Automaton/Plugin/Filter/Unshorten.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 1 / 1 totaltotal 45.8% 22 / 48 CC 3 SCAR 11.3
CC
3
Cov
41%
go
6.0
_logger
6.0
_unshorten
2.0
CRAP 3.1
« Automaton/Plugin/Action/NZB.pm ↑ Summary Automaton/Plugin/Source/File.pm »
1 package App::Automaton::Plugin::Filter::Unshorten;
2  
3 # ABSTRACT: Expansion of shortneded URLs
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub go {
Subroutine go: not called CC=2 SCAR=17.9
Pod documented
13 0 my $self = shift;
14 0 my $in = shift;
15 0 my $bits = shift;
16 0 my $d = $in->{debug};
17
18 0 my @patterns = (
19 "http[s]?:\/\/t.co\/.{10}", #twitter
20 "http[s]?:\/\/goo.gl\/[a-z,A-Z,0-9]*", # google
21 "http[s]?:\/\/bit.ly\/[a-z,A-Z,0-9]*", #http://bit.ly/1vsPSjP
22 "http[s]?:\/\/bit.do\/[a-z,A-Z,0-9]*", #http://bit.do/UVBz
23 "http[s]?:\/\/ow.ly\/[a-z,A-Z,0-9]*", # http://ow.ly/FiTXV
24 "http[s]?:\/\/tr.im\/[a-z,A-Z,0-9]*", # https://tr.im/23498
25 "http[s]?:\/\/youtu.be\/.{11}",
26 "http[s]?:\/\/t.ted.com\/.{7}",
27 );
28
29 0 my $pattern_string = join('|', @patterns);
30
31 0 foreach my $bit (@$bits) {
32 0 $bit =~ s/($pattern_string)/_unshorten($d, $1)/eg;
33 }
34  
35 0 return 1;
36 }
37  
38 0 ▶sub _unshorten {
Subroutine _unshorten: not called CC=1 SCAR=6.9
39 0 my $d = shift;
40 0 my $input = shift;
41 0 my $ua = LWP::UserAgent->new;
42 0 my $r = $ua->head($input);
43 0 my $new_url = $r->base;
44 0 _logger($d, "Expanding $input to $new_url");
45 0 return $new_url;
46 }
47  
48 0 ▶sub _logger {
Subroutine _logger: not called CC=2 SCAR=17.9
49 0 my $level = shift;
50 0 my $message = shift;
51 0 ▶ print "$message\n" if $level;
Branch: 1 branch
BranchTrueFalseTotal
if $level 0 0 0
52 0 return 1;
53 }
54  
55 1 1;
56  
57 __END__
« Automaton/Plugin/Action/NZB.pm ↑ Summary Automaton/Plugin/Source/File.pm »