| 1 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package App::Nopaste::Command; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: command-line utility for L<App::Nopaste> | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '1.013'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Getopt::Long::Descriptive (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use App::Nopaste; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Module::Runtime 'use_module'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use namespace::clean 0.19; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub new_with_options { | ||||||||||||||||||||||||||
|
Subroutine
new_with_options: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 0 | my ($opt, $usage) = Getopt::Long::Descriptive::describe_options( | |||||||||||||||||||||||||||
| 17 | "$0 %o", | ||||||||||||||||||||||||||||
| 18 | ['help|usage|?|h', 'Prints this usage information' ], | ||||||||||||||||||||||||||||
| 19 | ['desc|description|d=s', | ||||||||||||||||||||||||||||
| 20 | 'The one line description of your paste. The default is usually the first few characters of your text.' | ||||||||||||||||||||||||||||
| 21 | ], | ||||||||||||||||||||||||||||
| 22 | ['nick|nickname|name|n=s', 'Your nickname, usually displayed with the paste.'], | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | ['lang|language|l=s', 'The language of the nopaste. Default: perl.', | ||||||||||||||||||||||||||||
| 25 | { default => 'perl' }, | ||||||||||||||||||||||||||||
| 26 | ], | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | ['chan|channel|c=s', | ||||||||||||||||||||||||||||
| 29 | 'The channel for the nopaste, not always relevant. Usually tied to a pastebot in that channel which will announce your paste.', | ||||||||||||||||||||||||||||
| 30 | ], | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | ['services|service|s=s', | ||||||||||||||||||||||||||||
| 33 | 'The nopaste services to try, in order. You may also specify this in the env var NOPASTE_SERVICES.', | ||||||||||||||||||||||||||||
| 34 | ], | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | ['list_services|list|L', 'List available nopaste services'], | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | ['copy|x', 'If specified, automatically copy the URL to your clipboard.'], | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | ['paste|p', 'If specified, use only the clipboard as input.'], | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | ['open_url|open|o', 'If specified, automatically open the URL using Browser::Open.'], | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ['quiet|q', 'If specified, do not warn or complain about broken services.'], | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | ['private', 'If specified, paste privately to services where possible.'], | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | print($usage->text), exit if $opt->help; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | my $self = $class->new({ | ||||||||||||||||||||||||||||
| 52 | extra_argv => [@ARGV], | ||||||||||||||||||||||||||||
| 53 | 0 | map { $_ => $opt->$_ } qw( | |||||||||||||||||||||||||||
| 54 | desc nick lang chan list_services copy paste open_url quiet private services | ||||||||||||||||||||||||||||
| 55 | ), | ||||||||||||||||||||||||||||
| 56 | }); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 17 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 17 | my $class = shift; | |||||||||||||||||||||||||||
| 61 | 17 | my $self; | |||||||||||||||||||||||||||
| 62 | 17 | ▶ | if (!ref $_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 2 | $self = { @_ }; | |||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 15 | $self = $_[0] | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | $self->{services} = [ split /\s+/, $self->{services} ] | ||||||||||||||||||||||||||||
| 69 | 17 | ▶ | if defined $self->{services} && !ref $self->{services}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"services"} and not ref $self->{"services"}
MC/DC0%0/2
defined $self->{"services"} and not ref $self->{"services"}
defined $self->{"services"}
not ref $self->{"services"}
Truth table66%2/3
A and not(B)
A= defined $self->{"services"}B= not ref $self->{"services"}
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 17 | bless $self, $class; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 17 | return $self | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 3 | my @acc = qw( | |||||||||||||||||||||||||||
| 76 | desc nick lang chan list_services copy paste open_url quiet private usage | ||||||||||||||||||||||||||||
| 77 | extra_argv services | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | 3 | for my $a (@acc) { | |||||||||||||||||||||||||||
| 80 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 56 | ▶ | *{__PACKAGE__ . '::' . $a } = sub { $_[0]->{$a} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | 39 | } | |||||||||||||||||||||||||||
| 84 | 4 | ▶ | sub filename { | ||||||||||||||||||||||||||
|
Subroutine
filename: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 4 | my @files = @{ $self->extra_argv }; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | return undef unless @files; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | return undef if $self->paste or $files[0] eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->paste or $files[0] eq "-"
MC/DC0%0/2
$self->paste or $files[0] eq "-"
$self->paste
$files[0] eq "-"
Truth table33%1/3
A or B
A= $self->pasteB= $files[0] eq "-"
| |||||||||||||||||||||||||||||
| 90 | 2 | return $files[0]; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 3 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=8 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | ▶ | if ($self->list_services) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | for (sort App::Nopaste->plugins) { | |||||||||||||||||||||||||||
| 98 | 0 | s/App::Nopaste::Service::(\w+)$/$1/; | |||||||||||||||||||||||||||
| 99 | 0 | print $_, "\n"; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | exit 0; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | my $text = $self->read_text; | |||||||||||||||||||||||||||
| 105 | 2 | utf8::decode($text); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | my %args = map { $_ => $self->$_ } @acc, qw(filename); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | ▶ | $args{text} ||= $text; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"text"} ||= $text
MC/DC0%0/2
$args{"text"} ||= $text
$args{"text"}
$text
Truth table33%1/3
A ||= B
A= $args{"text"}B= $text
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $args{error_handler} = $args{warn_handler} = sub { } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 112 | 2 | ▶ | if $self->quiet; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 2 | my $url = App::Nopaste->nopaste(%args); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | ▶ | if ($self->copy) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | use_module('Clipboard')->import; | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | Clipboard->copy_to_all_selections($url); | |||||||||||||||||||||||||||
| 120 | 0 | 1; | |||||||||||||||||||||||||||
| 121 | } or Clipboard->copy($url); | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | ▶ | if ($self->open_url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | use_module('Browser::Open'); | |||||||||||||||||||||||||||
| 126 | 0 | Browser::Open::open_browser($url); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | return $url; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 2 | ▶ | sub read_text { | ||||||||||||||||||||||||||
|
Subroutine
read_text: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 2 | ▶ | if ($self->paste && @{ $self->extra_argv }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->paste and @{$self->extra_argv;}
MC/DC50%1/2
$self->paste and @{$self->extra_argv;}
$self->paste
@{$self->extra_argv;}
Truth table66%2/3
A and B
A= $self->pasteB= @{$self->extra_argv;}
| |||||||||||||||||||||||||||||
| 136 | 1 | die "You may not specify --paste and files simultaneously.\n"; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | if ($self->paste) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | use_module('Clipboard')->import; | |||||||||||||||||||||||||||
| 141 | 0 | return Clipboard->paste; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | local @ARGV = @{ $self->extra_argv }; | |||||||||||||||||||||||||||
| 145 | 0 | local $/; | |||||||||||||||||||||||||||
| 146 | 0 | return <>; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 3 | 1; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||