App/Command.pm

filter: Statementstmt 70.2% 33 / 47 Branchbran 50.0% 9 / 18 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 60.0% 9 / 15 Podpod 20.0% 2 / 10 totaltotal 53.3% 56 / 105 CC 13 SCAR 19.7
CC
13
Cov
61%
validate_args
15.1
validate_file_params
6.0
validate_project_workdir
6.0
CRAP 7.2
« App/DocumentApi.pm ↑ Summary App/Command/document.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Smartcat::App::Command;
5 2 ▶use App::Cmd::Setup -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
11 return (
12 #[ 'config:s' => 'Config file path' ],
13 2 [ 'token-id:s' => 'Smartcat account id' ],
14 [ 'token:s' => 'API token' ],
15 [ 'log:s' => 'Log file path' ],
16 [ 'base-url:s' => 'Base Smartcat URL' ],
17 [ 'debug' => 'Debug mode' ]
18 );
19 }
20  
21 2 ▶sub project_id_opt_spec {
Subroutine project_id_opt_spec: called CC=1 SCAR=0.0
Pod undocumented
22 2 return ( [ 'project-id:s' => 'Project Id' ], );
23 }
24  
25 0 ▶sub project_workdir_opt_spec {
Subroutine project_workdir_opt_spec: not called CC=1 SCAR=6.9
Pod undocumented
26 0 return ( [ 'project-workdir:s' => 'Project translation files path' ], );
27 }
28  
29 0 ▶sub file_params_opt_spec {
Subroutine file_params_opt_spec: not called CC=1 SCAR=6.9
Pod undocumented
30 return (
31 0 [ 'filetype:s' => 'Type of translation files' ],
32 );
33 }
34  
35 0 ▶sub extract_id_from_name_opt_spec {
Subroutine extract_id_from_name_opt_spec: not called CC=1 SCAR=6.9
Pod undocumented
36 return (
37 0 [ 'extract-id-from-name' => 'Extract stable external document identifiers from filenames in "name---id.ext" format for comparison and automatic renaming' ],
38 );
39 }
40  
41 0 ▶sub external_tag_opt_spec {
Subroutine external_tag_opt_spec: not called CC=1 SCAR=6.9
Pod undocumented
42 return (
43 0 ['external-tag:s' => 'Set custom external tag for project. Default value: "source:Serge"']
44 );
45 }
46  
47 0 ▶sub validate_file_params {
Subroutine validate_file_params: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my ( $self, $opt, $args ) = @_;
49 0 my $rundata = $self->app->{rundata};
50 0 ▶ $rundata->{filetype} = defined $opt->{filetype} ? $opt->{filetype} : '.po';
Branch: 1 branch
BranchTrueFalseTotal
defined $opt->{'filetype'} ? : 0 0 0
51 }
52  
53 2 ▶sub validate_project_id {
Subroutine validate_project_id: called CC=2 SCAR=7.0
Pod undocumented
54 2 my ( $self, $opt, $args ) = @_;
55 2 my $rundata = $self->app->{rundata};
56 $self->usage_error("'project_id' is required")
57 2 ▶ unless defined $opt->{project_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"project_id"} 0 2 2
58 2 $rundata->{project_id} = $opt->{project_id};
59 }
60  
61 0 ▶sub validate_project_workdir {
Subroutine validate_project_workdir: not called CC=2 SCAR=17.9
Pod undocumented
62 0 my ( $self, $opt, $args ) = @_;
63  
64 0 my $rundata = $self->app->{rundata};
65 $self->app->usage_error(
66 "'project_workdir', which is set to '$opt->{project_workdir}', does not point to a valid directory"
67 0 ▶ ) unless -d $opt->{project_workdir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $opt->{"project_workdir"} 0 0 0
68 0 $rundata->{project_workdir} = abs_path( $opt->{project_workdir} );
69 }
70  
71 2 ▶sub validate_args {
Subroutine validate_args: called CC=10 SCAR=27.2
Pod documented
72 2 my ( $self, $opt, $args ) = @_;
73  
74 2 my $app = $self->app;
75 2 my $rundata = $self->app->{rundata};
76  
77 2 ▶ if ( defined $opt->{token_id} && defined $opt->{token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"token_id"} and defined $opt->{"token"}) 0 2 2
Condition33%1/3
defined $opt->{"token_id"} and defined $opt->{"token"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $opt->{"token_id"} and defined $opt->{"token"}
defined $opt->{"token_id"} defined $opt->{"token"}
Truth table33%1/3
A and B
A= defined $opt->{"token_id"}B= defined $opt->{"token"}
ABresult
0X0
100
111
78 0 $app->{config}->{username} = $opt->{token_id};
79 0 $app->{config}->{password} = $opt->{token};
80 }
81  
82 2 ▶ if ( defined $opt->{base_url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"base_url"}) 0 2 2
83 0 $app->{config}->{base_url} = $opt->{base_url};
84 }
85  
86 2 ▶ if ( defined $opt->{log} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"log"}) 1 1 2
87 $self->usage_error(
88 "directory of 'log', which is set to '$opt->{log}', does not point to a valid directory"
89 1 ▶ ) unless -d dirname( $opt->{log} ) && -w _;
Branch: 1 branch
BranchTrueFalseTotal
unless -d dirname($opt->{"log"}) and -w _ 0 1 1
Condition33%1/3
-d dirname($opt->{"log"}) and -w _
!ll&&!rl&&r
001
MC/DC0%0/2
-d dirname($opt->{"log"}) and -w _
-d dirname($opt->{"log"}) -w _
Truth table33%1/3
A and B
A= -d dirname($opt->{"log"})B= -w _
ABresult
0X0
100
111
90 1 $app->{config}->{log} = $opt->{log};
91 }
92  
93 $self->usage_error(
94 "set auth params via 'config' command first or provide options '--token-id' and '--token'"
95 )
96 unless ( defined $app->{config}->username
97 2 ▶ && defined $app->{config}->password );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $app->{"config"}->username and defined $app->{"config"}->password 0 2 2
Condition33%1/3
defined $app->{"config"}->username and defined $app->{"config"}->password
!ll&&!rl&&r
002
MC/DC0%0/2
defined $app->{"config"}->username and defined $app->{"config"}->password
defined $app->{"config"}->username defined $app->{"config"}->password
Truth table33%1/3
A and B
A= defined $app->{"config"}->usernameB= defined $app->{"config"}->password
ABresult
0X0
100
111
98  
99 2 ▶ $rundata->{debug} = 1 if defined $opt->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"debug"} 1 1 2
100  
101 2 $app->init;
102 }
103  
104 2 1;
« App/DocumentApi.pm ↑ Summary App/Command/document.pm »