| 1 | package Tapper::CLI::API::Command::upload; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Tapper::CLI::API::Command::upload::VERSION = '5.0.8'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use parent 'App::Cmd::Command'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Tapper::Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::Slurp 'slurp'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub abstract { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | 'Upload and attach a file to a report' | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | [ "verbose", "some more informational output" ], | |||||||||||||||||||||||||||||||||||||||||
| 24 | [ "reportid=s", "INT; the testrun id to change", ], | ||||||||||||||||||||||||||||||||||||||||||
| 25 | [ "file=s", "STRING; the file to upload, use '-' for STDIN", ], | ||||||||||||||||||||||||||||||||||||||||||
| 26 | [ "filename=s", "STRING; alternate file name, especially when reading from STDIN", ], | ||||||||||||||||||||||||||||||||||||||||||
| 27 | [ "reportserver=s", "STRING; use this host for upload", ], | ||||||||||||||||||||||||||||||||||||||||||
| 28 | [ "reportport=s", "STRING; use this port for upload", ], | ||||||||||||||||||||||||||||||||||||||||||
| 29 | [ "contenttype=s", "STRING; content-type, default 'plain', use 'application/octet-stream' for binaries", ], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | sub usage_desc | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage_desc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $allowed_opts = join ' ', map { '--'.$_ } _allowed_opts(); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | "tapper-api upload --reportid=s --file=s [ --contenttype=s ]"; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | sub _allowed_opts | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_allowed_opts: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my @allowed_opts = map { $_->[0] } opt_spec(); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | sub validate_args | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_args: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # -- file constraints -- | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $file = $opt->{file}; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $file_ok = $file && ($file eq '-' || -r $file); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$file && ($file eq '-' || -r $file)
$file eq "-" or -r $file
MC/DC0%0/3
$file && ($file eq '-' || -r $file)
$file
$file eq "-"
-r $file
Truth table0%0/4
A && B or C
A= $fileB= $file eq "-"C= -r $file
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | say "Missing argument --file" unless $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | say "Error: file '".($file//"")."' must be readable or STDIN." unless $file_ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$file // ""
MC/DC0%0/1
$file // ""
$file
Truth table0%0/2
A
A= $file
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # -- report constraints -- | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $reportid = $opt->{reportid}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $report_ok = $reportid && $reportid =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$reportid && $reportid =~ /^\d+$/
MC/DC0%0/2
$reportid && $reportid =~ /^\d+$/
$reportid
$reportid =~ /^\d+$/
Truth table0%0/3
A && B
A= $reportidB= $reportid =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | say "Missing argument --reportid" unless $reportid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | say "Error: Strange target report (id '".($reportid//"")."')." unless $report_ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$reportid // ""
MC/DC0%0/1
$reportid // ""
$reportid
Truth table0%0/2
A
A= $reportid
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return 1 if $opt->{reportid} && $file_ok && $report_ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opt->{"reportid"} and $file_ok and $report_ok
$opt->{"reportid"} and $file_ok
MC/DC0%0/3
$opt->{"reportid"} and $file_ok and $report_ok
$opt->{"reportid"}
$file_ok
$report_ok
Truth table0%0/4
A and B and C
A= $opt->{"reportid"}B= $file_okC= $report_ok
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | die $self->usage->text; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | sub execute | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->upload ($opt, $args); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | sub _read_file | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $file = $opt->{file}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # read from file or STDIN if filename == '-' | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($file eq '-') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $content = slurp (\*STDIN); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $content = slurp ($file); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | sub upload | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $host = $opt->{reportserver} || Tapper::Config->subconfig->{report_server}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt->{'reportserver'} || 'Tapper::Config'->subconfig->{'report_server'}
MC/DC0%0/2
$opt->{'reportserver'} || 'Tapper::Config'->subconfig->{'report_server'}
$opt->{'reportserver'}
'Tapper::Config'->subconfig->{'report_server'}
Truth table0%0/3
A || B
A= $opt->{'reportserver'}B= 'Tapper::Config'->subconfig->{'report_server'}
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my $port = $opt->{reportport} || Tapper::Config->subconfig->{report_api_port}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opt->{'reportport'} || 'Tapper::Config'->subconfig->{'report_api_port'}
MC/DC0%0/2
$opt->{'reportport'} || 'Tapper::Config'->subconfig->{'report_api_port'}
$opt->{'reportport'}
'Tapper::Config'->subconfig->{'report_api_port'}
Truth table0%0/3
A || B
A= $opt->{'reportport'}B= 'Tapper::Config'->subconfig->{'report_api_port'}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $reportid = $opt->{reportid}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $file = $opt->{file}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $filename = $opt->{filename}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $contenttype = $opt->{contenttype} || 'plain'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt->{'contenttype'} || 'plain'
MC/DC0%0/1
$opt->{'contenttype'} || 'plain'
$opt->{'contenttype'}
Truth table0%0/2
A
A= $opt->{'contenttype'}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $content = $self->_read_file($opt, $args); | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $cmdline = "#! upload $reportid ".($filename || $file)." $contenttype\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$filename || $file
MC/DC0%0/2
$filename || $file
$filename
$file
Truth table0%0/3
A || B
A= $filenameB= $file
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $REMOTEAPI = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($REMOTEAPI) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | #my $oldfh = select $REMOTEAPI; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | print $REMOTEAPI $cmdline; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | print $REMOTEAPI $content; | |||||||||||||||||||||||||||||||||||||||||
| 108 | #select($oldfh); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | close ($REMOTEAPI); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | say "Cannot open remote receiver $host:$port."; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # perl -Ilib bin/tapper-api upload --reportid=552 --file ~/xyz | ||||||||||||||||||||||||||||||||||||||||||
| 117 | # perl -Ilib bin/tapper-api upload --reportid=552 --file=$HOME/xyz | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # dmesg | perl -Ilib bin/tapper-api upload --reportid=552 --file=- --filename="dmesg" | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||||||||||||||||