Nopaste.pm

filter: Statementstmt 86.4% 51 / 59 Branchbran 50.0% 13 / 26 Conditioncond 21.4% 3 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 83.3% 10 / 12 Podpod 50.0% 1 / 2 totaltotal 63.9% 78 / 122 CC 20 SCAR 35.1
CC
20
Cov
68%
nopaste
51.1
__ANON__
2.0
__ANON__
2.0
CRAP 33.4
« Nopaste/Service/ssh.pm ↑ Summary Nopaste/Service/Gist.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package App::Nopaste; # git description: 1.012-12-g5acc073
4 # ABSTRACT: Easy access to any pastebin
5 # KEYWORDS: application executable paste output pastebin debugging
6  
7 4 our $VERSION = '1.013';
8  
9 4 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Module::Pluggable search_path => 'App::Nopaste::Service', sub_name => '_plugins';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Class::Load 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use namespace::clean 0.19;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 our @EXPORT_OK = 'nopaste';
16  
17 1 ▶sub plugins { goto \&_plugins };
Subroutine plugins: called CC=1 SCAR=0.0
Pod undocumented
18  
19 2 ▶sub nopaste {
Subroutine nopaste: called CC=20 SCAR=39.3
Pod documented
20 # process arguments
21 # allow "nopaste($text)"
22 2 ▶ unshift @_, 'text' if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 2 2
23  
24 # only look for $self if we have odd number of arguments
25 2 my $self;
26 2 ▶ $self = @_ % 2 ? shift : __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 2 0 2
27  
28 # everything else
29 2 my %args = @_;
30  
31 $args{services} = defined($ENV{NOPASTE_SERVICES})
32 && [split ' ', $ENV{NOPASTE_SERVICES}]
33 2 ▶ if !defined($args{services});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"services"} 0 2 2
Condition0%0/2
defined $ENV{'NOPASTE_SERVICES'} && [split(' ', $ENV{'NOPASTE_SERVICES'}, 0)]
!ll
00
MC/DC0%0/1
defined $ENV{'NOPASTE_SERVICES'} && [split(' ', $ENV{'NOPASTE_SERVICES'}, 0)]
defined $ENV{'NOPASTE_SERVICES'}
Truth table0%0/2
A
A= defined $ENV{'NOPASTE_SERVICES'}
Aresult
00
11
34  
35 $args{nick} = $ENV{NOPASTE_NICK} || $ENV{USER}
36 2 ▶ if !defined($args{nick});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"nick"} 0 2 2
Condition0%0/3
$ENV{'NOPASTE_NICK'} || $ENV{'USER'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'NOPASTE_NICK'} || $ENV{'USER'}
$ENV{'NOPASTE_NICK'} $ENV{'USER'}
Truth table0%0/3
A || B
A= $ENV{'NOPASTE_NICK'}B= $ENV{'USER'}
ABresult
1X1
011
000
37  
38  
39 2 my $using_default = 0;
40 2 ▶ unless (ref($args{services}) eq 'ARRAY' && @{$args{services}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"services"} eq "ARRAY" and @{$args{"services"};}) 0 2 2
Condition33%1/3
ref $args{"services"} eq "ARRAY" and @{$args{"services"};}
!ll&&!rl&&r
002
MC/DC0%0/2
ref $args{"services"} eq "ARRAY" and @{$args{"services"};}
ref $args{"services"} eq "ARRAY" @{$args{"services"};}
Truth table33%1/3
A and B
A= ref $args{"services"} eq "ARRAY"B= @{$args{"services"};}
ABresult
0X0
100
111
41 0 $using_default = 1;
42 0 $args{services} = [ $self->plugins ];
43 }
44  
45 2 ▶ @{ $args{services} }
Branch: 1 branch
BranchTrueFalseTotal
@{$args{"services"};} or Carp::croak("No App::Nopaste::Service module found") 2 0 2
46 or Carp::croak "No App::Nopaste::Service module found";
47  
48 defined $args{text}
49 2 ▶ or Carp::croak "You must specify the text to nopaste";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"text"} or Carp::croak("You must specify the text to nopaste") 2 0 2
50  
51 0 ▶ $args{error_handler} ||= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 my ($msg, $srv) = @_;
53 0 $msg =~ s/\n*$/\n/;
54 0 warn "$srv: $msg"
55 2 ▶ };
Condition33%1/3
$args{"error_handler"} ||= sub { my($msg, $srv) = @_; $msg =~ s/\n*$/\n/; warn "${srv}: $msg"; }
l!l&&r!l&&!r
020
MC/DC0%0/2
$args{"error_handler"} ||= sub { my($msg, $srv) = @_; $msg =~ s/\n*$/\n/; warn "${srv}: $msg"; }
$args{"error_handler"} sub { my($msg, $srv) = @_; $msg =~ s/\n*$/\n/; warn "${srv}: $msg"; }
Truth table33%1/3
A ||= B
A= $args{"error_handler"}B= sub { my($msg, $srv) = @_; $msg =~ s/\n*$/\n/; warn "${srv}: $msg"; }
ABresult
1X1
011
000
56  
57 # try to paste to each service in order
58 2 for my $service (@{ $args{services} }) {
59 2 ▶ $service = "App::Nopaste::Service::$service"
Branch: 1 branch
BranchTrueFalseTotal
unless $service =~ /^App::Nopaste::Service/ 0 2 2
60 unless $service =~ /^App::Nopaste::Service/;
61  
62 4 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 2 my @ret = eval {
64  
65 0 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 $args{warn_handler}->($_[0], $service);
67 2 ▶ } if $args{warn_handler};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"warn_handler"} 0 2 2
68  
69 2 load_class($service);
70  
71 2 ▶ next unless $service->available(%args);
Branch: 1 branch
BranchTrueFalseTotal
unless $service->available(%args) 0 2 2
72 2 ▶ next if $using_default && $service->forbid_in_default;
Branch: 1 branch
BranchTrueFalseTotal
if $using_default and $service->forbid_in_default 0 2 2
Condition33%1/3
$using_default and $service->forbid_in_default
!ll&&!rl&&r
200
MC/DC0%0/2
$using_default and $service->forbid_in_default
$using_default $service->forbid_in_default
Truth table33%1/3
A and B
A= $using_defaultB= $service->forbid_in_default
ABresult
0X0
100
111
73 2 $service->nopaste(%args);
74 };
75  
76 2 ▶ @ret = (0, $@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
77  
78 # success!
79 2 ▶ return $ret[1] if $ret[0];
Branch: 1 branch
BranchTrueFalseTotal
if $ret[0] 2 0 2
80  
81 # failure!
82 0 $args{error_handler}->($ret[1], $service);
83 }
84  
85 0 Carp::croak "No available App::Nopaste::Service modules found";
86 }
87  
88 4 1;
89  
90 __END__
« Nopaste/Service/ssh.pm ↑ Summary Nopaste/Service/Gist.pm »