Tinyish.pm

filter: Statementstmt 34.5% 19 / 55 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 23.5% 4 / 17 Podpod 0.0% 0 / 12 totaltotal 24.4% 23 / 94 CC 7 SCAR 21.5
CC
7
Cov
29%
_backend_for
30.0
backends
6.0
configure_backend
6.0
CRAP 8.6
« Tinyish/LWP.pm ↑ Summary Tinyish/HTTPTiny.pm »
1 package HTTP::Tinyish;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.20';
7  
8 1 our $PreferredBackend; # for tests
9 1 our @Backends = map "HTTP::Tinyish::$_", qw( LWP HTTPTiny Curl Wget );
10 1 my %configured;
11  
12 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my($class, %attr) = @_;
14 0 bless \%attr, $class;
15 }
16  
17 1 for my $method (qw/get head put post delete mirror patch/) {
18 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 0 ▶ eval <<"HERE";
Subroutine delete: not called CC=1 SCAR=6.0
Subroutine get: not called CC=1 SCAR=6.0
Subroutine head: not called CC=1 SCAR=6.0
Subroutine mirror: not called CC=1 SCAR=6.0
Subroutine patch: not called CC=1 SCAR=6.0
Subroutine post: not called CC=1 SCAR=6.0
Subroutine put: not called CC=1 SCAR=6.0
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
20 sub $method {
21 my \$self = shift;
22 \$self->_backend_for(\$_[0])->$method(\@_);
23 }
24 HERE
25 }
26  
27 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod undocumented
28 0 my $self = shift;
29 0 $self->_backend_for($_[1])->request(@_);
30 }
31  
32 0 ▶sub _backend_for {
Subroutine _backend_for: not called CC=5 SCAR=34.0
33 0 my($self, $url) = @_;
34  
35 0 my($scheme) = $url =~ m!^(https?):!;
36 0 ▶ Carp::croak "URL Scheme '$url' not supported." unless $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme 0 0 0
37  
38 0 for my $backend ($self->backends) {
39 0 ▶ $self->configure_backend($backend) or next;
Branch: 1 branch
BranchTrueFalseTotal
$self->configure_backend($backend) or next 0 0 0
40 0 ▶ if ($backend->supports($scheme)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($backend->supports($scheme)) 0 0 0
41 0 return $backend->new(%$self);
42 }
43 }
44  
45 0 Carp::croak "No backend configured for scheme $scheme";
46 }
47  
48 0 ▶sub backends {
Subroutine backends: not called CC=2 SCAR=17.9
Pod undocumented
49 0 ▶ $PreferredBackend ? ($PreferredBackend) : @Backends;
Branch: 1 branch
BranchTrueFalseTotal
$HTTP::Tinyish::PreferredBackend ? : 0 0 0
50 }
51  
52 0 ▶sub configure_backend {
Subroutine configure_backend: not called CC=2 SCAR=17.9
Pod undocumented
53 0 my($self, $backend) = @_;
54 0 ▶ unless (exists $configured{$backend}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $configured{$backend}) 0 0 0
55 $configured{$backend} =
56 0 eval { require_module($backend); $backend->configure };
57 }
58 0 $configured{$backend};
59 }
60  
61 0 ▶sub require_module {
Subroutine require_module: not called CC=1 SCAR=6.9
Pod undocumented
62 0 local $_ = shift;
63 0 s!::!/!g;
64 0 require "$_.pm";
65 }
66  
67 1 1;
68  
69 __END__
« Tinyish/LWP.pm ↑ Summary Tinyish/HTTPTiny.pm »