| 1 | package Tapper::CLI::API::Command::download; | ||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 2 | $Tapper::CLI::API::Command::download::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 | 'Download a file from 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 where the file is attached" ], | ||||||||||||||||||||||||||||
| 25 | [ "file=s", "STRING; the filename to download" ], | ||||||||||||||||||||||||||||
| 26 | [ "nth=s", "INT; the n-th file if there is more than one with same name; default 0" ], | ||||||||||||||||||||||||||||
| 27 | [ "saveas=s", "STRING; where to write result; default print to STDOUT" ], | ||||||||||||||||||||||||||||
| 28 | [ "reportserver=s", "STRING; use this host for upload" ], | ||||||||||||||||||||||||||||
| 29 | [ "reportport=s", "STRING; use this port for upload" ], | ||||||||||||||||||||||||||||
| 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 dowload --reportid=s --file=s [ --saveas=s ] [ --nth=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=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # -- file constraints -- | ||||||||||||||||||||||||||||
| 49 | 0 | my $file = $opt->{file}; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | say "Missing argument --file" unless $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # -- report constraints -- | ||||||||||||||||||||||||||||
| 53 | 0 | my $reportid = $opt->{reportid}; | |||||||||||||||||||||||||||
| 54 | 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+$/
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | say "Missing argument --reportid" unless $reportid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 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
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return 1 if $opt->{reportid} && $report_ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->{"reportid"} and $report_ok
MC/DC0%0/2
$opt->{"reportid"} and $report_ok
$opt->{"reportid"}
$report_ok
Truth table0%0/3
A and B
A= $opt->{"reportid"}B= $report_ok
| |||||||||||||||||||||||||||||
| 59 | 0 | die $self->usage->text; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub execute | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | $self->download ($opt, $args); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub download | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
download: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 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'}
| |||||||||||||||||||||||||||||
| 74 | 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'}
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $reportid = $opt->{reportid}; | |||||||||||||||||||||||||||
| 77 | 0 | my $file = $opt->{file}; | |||||||||||||||||||||||||||
| 78 | 0 | my $saveas = $opt->{saveas}; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $nth = $opt->{nth} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opt->{'nth'} || 0
MC/DC0%0/1
$opt->{'nth'} || 0
$opt->{'nth'}
Truth table0%0/2
A
A= $opt->{'nth'}
| |||||||||||||||||||||||||||||
| 80 | 0 | my $content; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my $cmdline = "#! download $reportid $file $nth\n"; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my $REMOTEAPI = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port); | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($REMOTEAPI) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | print $REMOTEAPI $cmdline; | |||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 0 | local $/; | |||||||||||||||||||||||||||
| 89 | 0 | $content = <$REMOTEAPI>; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | close ($REMOTEAPI); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # write to file or STDOUT | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($saveas) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | open my $SAVEAS, ">", $saveas or die "Can not write to file '$saveas'"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | print $SAVEAS $content; | |||||||||||||||||||||||||||
| 97 | 0 | close $SAVEAS; | |||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||
| 99 | 0 | print $content; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||
| 103 | 0 | say "Cannot open remote receiver $host:$port."; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # perl -Ilib bin/tapper-api download --reportid=552 --file ~/xyz --saveas=/tmp/myxyz | ||||||||||||||||||||||||||||
| 108 | # perl -Ilib bin/tapper-api download --reportid=552 --file ~/xyz --nth=1 --saveas=/tmp/myxyz | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||