blib/lib/Tapper/CLI/API/Command/download.pm

filter: Statementstmt 42.0% 29 / 69 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 56.2% 9 / 16 Podpod 83.3% 5 / 6 totaltotal 32.8% 43 / 131 CC 14 SCAR 35.3
CC
14
Cov
29%
validate_args
72.0
download
56.0
abstract
2.0
CRAP 34.0
« blib/lib/Tapper/CLI/Host.pm ↑ Summary blib/lib/Tapper/CLI/Base.pm »
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
BranchTrueFalseTotal
unless $file 0 0 0
51  
52 # -- report constraints --
53 0 my $reportid = $opt->{reportid};
54 0 ▶ my $report_ok = $reportid && $reportid =~ /^\d+$/;
Condition0%0/3
$reportid && $reportid =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$reportid && $reportid =~ /^\d+$/
$reportid $reportid =~ /^\d+$/
Truth table0%0/3
A && B
A= $reportidB= $reportid =~ /^\d+$/
ABresult
0X0
100
111
55 0 ▶ say "Missing argument --reportid" unless $reportid;
Branch: 1 branch
BranchTrueFalseTotal
unless $reportid 0 0 0
56 0 ▶ say "Error: Strange target report (id '".($reportid//"")."')." unless $report_ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $report_ok 0 0 0
Condition0%0/2
$reportid // ""
l!l
00
MC/DC0%0/1
$reportid // ""
$reportid
Truth table0%0/2
A
A= $reportid
Aresult
11
00
57  
58 0 ▶ return 1 if $opt->{reportid} && $report_ok;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"reportid"} and $report_ok 0 0 0
Condition0%0/3
$opt->{"reportid"} and $report_ok
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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'}
l!l&&r!l&&!r
000
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'}
ABresult
1X1
011
000
74 0 ▶ my $port = $opt->{reportport} || Tapper::Config->subconfig->{report_api_port};
Condition0%0/3
$opt->{'reportport'} || 'Tapper::Config'->subconfig->{'report_api_port'}
l!l&&r!l&&!r
000
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'}
ABresult
1X1
011
000
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
l!l
00
MC/DC0%0/1
$opt->{'nth'} || 0
$opt->{'nth'}
Truth table0%0/2
A
A= $opt->{'nth'}
Aresult
11
00
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
BranchTrueFalseTotal
if ($REMOTEAPI) { } 0 0 0
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
BranchTrueFalseTotal
if ($saveas) { } 0 0 0
95 0 ▶ open my $SAVEAS, ">", $saveas or die "Can not write to file '$saveas'";
Branch: 1 branch
BranchTrueFalseTotal
open my $SAVEAS, ">", $saveas or die "Can not write to file '${saveas}'" 0 0 0
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__
« blib/lib/Tapper/CLI/Host.pm ↑ Summary blib/lib/Tapper/CLI/Base.pm »