| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/2
defined $ENV{'NOPASTE_SERVICES'} && [split(' ', $ENV{'NOPASTE_SERVICES'}, 0)]
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'}
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | $args{nick} = $ENV{NOPASTE_NICK} || $ENV{USER} | ||||||||||||||||||||||||||||
| 36 | 2 | ▶ | if !defined($args{nick}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{'NOPASTE_NICK'} || $ENV{'USER'}
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'}
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | my $using_default = 0; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | unless (ref($args{services}) eq 'ARRAY' && @{$args{services}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args{"services"} eq "ARRAY" and @{$args{"services"};}
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"};}
| |||||||||||||||||||||||||||||
| 41 | 0 | $using_default = 1; | |||||||||||||||||||||||||||
| 42 | 0 | $args{services} = [ $self->plugins ]; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | @{ $args{services} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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";
}
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";
}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | load_class($service); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | ▶ | next unless $service->available(%args); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | next if $using_default && $service->forbid_in_default; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$using_default and $service->forbid_in_default
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
| |||||||||||||||||||||||||||||
| 73 | 2 | $service->nopaste(%args); | |||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | @ret = (0, $@) if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # success! | ||||||||||||||||||||||||||||
| 79 | 2 | ▶ | return $ret[1] if $ret[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||