App/DocumentApi.pm

filter: Statementstmt 48.0% 36 / 75 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 5 totaltotal 37.6% 47 / 125 CC 13 SCAR 27.3
CC
13
Cov
36%
update_document
42.0
rename_document
20.0
get_document
12.0
CRAP 15.4
« App/ProjectApi.pm ↑ Summary App/Command.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 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶no utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package Smartcat::App::DocumentApi;
8  
9 2 ▶use Smartcat::Client::DocumentApi;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Smartcat::Client::Object::BilingualFileImportSetingsModel;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Smartcat::Client::Object::UploadDocumentPropertiesModel;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Smartcat::App::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 $Carp::Internal{ ('Smartcat::Client::DocumentApi') }++;
17 2 $Carp::Internal{ (__PACKAGE__) }++;
18  
19 2 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
22 1 my ( $class, $api, $rundata ) = @_;
23  
24 1 my $self = bless(
25 {
26 api => Smartcat::Client::DocumentApi->new($api),
27 rundata => $rundata
28 },
29 $class
30 );
31  
32 1 return $self;
33 }
34  
35 0 ▶sub rename_document {
Subroutine rename_document: not called CC=4 SCAR=30.0
Pod undocumented
36 0 my ( $self, $document_id, $document_name ) = @_;
37 0 ▶ return unless $document_id && $document_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $document_id and $document_name 0 0 0
Condition0%0/3
$document_id and $document_name
!ll&&!rl&&r
000
MC/DC0%0/2
$document_id and $document_name
$document_id $document_name
Truth table0%0/3
A and B
A= $document_idB= $document_name
ABresult
0X0
100
111
38  
39 0 $log->info("Renaming document '$document_id' to '$document_name'...");
40 0 my $utf8_name = $document_name;
41 0 utf8::encode($utf8_name);
42 0 my %args = (
43 document_id => $document_id,
44 name => $utf8_name,
45 );
46  
47 0 eval { $self->{api}->document_rename(%args) };
48 0 ▶ die $log->error(
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
49 sprintf(
50 "Failed to rename document '%s' to '%s'.\nError:\n%s",
51 $document_id, $document_name, format_error_message($@)
52 )
53 ) if $@;
54  
55 0 return;
56 }
57  
58 0 ▶sub update_document {
Subroutine update_document: not called CC=6 SCAR=37.4
Pod undocumented
59 0 my ( $self, $path, $document_id ) = @_;
60 0 ▶ return unless $path && $document_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $path and $document_id 0 0 0
Condition0%0/3
$path and $document_id
!ll&&!rl&&r
000
MC/DC0%0/2
$path and $document_id
$path $document_id
Truth table0%0/3
A and B
A= $pathB= $document_id
ABresult
0X0
100
111
61  
62 0 my $settings =
63 Smartcat::Client::Object::BilingualFileImportSetingsModel->new(
64 confirmMode => "atLastStage" );
65 0 my $doc_props =
66 Smartcat::Client::Object::UploadDocumentPropertiesModel->new(
67 bilingualFileImportSetings => $settings );
68  
69 0 $log->info("Updating document '$document_id' with '$path'...");
70 0 my $utf8_path = $path;
71 0 utf8::encode($utf8_path);
72 0 my %args = (
73 document_id => $document_id,
74 update_document_model => $doc_props,
75 file => $utf8_path
76 );
77  
78 $args{disassemble_algorithm_name} =
79 $self->{rundata}->{disassemble_algorithm_name}
80 0 ▶ if defined $self->{rundata}->{disassemble_algorithm_name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"rundata"}{"disassemble_algorithm_name"} 0 0 0
81 $args{preset_disassemble_algorithm} =
82 $self->{rundata}->{preset_disassemble_algorithm}
83 0 ▶ if defined $self->{rundata}->{preset_disassemble_algorithm};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"rundata"}{"preset_disassemble_algorithm"} 0 0 0
84  
85 0 my $document = eval { $self->{api}->document_update(%args) };
86 0 ▶ die $log->error(
Branch: 1 branch
BranchTrueFalseTotal
unless $document 0 0 0
87 sprintf(
88 "Failed to update document '%s' with '%s'.\nError:\n%s",
89 $document_id, $path, format_error_message($@)
90 )
91 ) unless $document;
92 }
93  
94 0 ▶sub get_document {
Subroutine get_document: not called CC=3 SCAR=24.8
Pod undocumented
95 0 my ( $self, $document_id ) = @_;
96 0 ▶ return unless $document_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $document_id 0 0 0
97  
98 0 $log->info("Getting document '$document_id'...");
99 0 my %args = ( document_id => $document_id, );
100  
101 0 my $document = eval { $self->{api}->document_get(%args); };
102 0 ▶ die $log->error(
Branch: 1 branch
BranchTrueFalseTotal
unless $document 0 0 0
103 sprintf(
104 "Failed to get document '%s'.\nError:\n%s",
105 $document_id, format_error_message($@)
106 )
107 ) unless $document;
108  
109 0 return $document;
110 }
111  
112 0 ▶sub delete_documents {
Subroutine delete_documents: not called CC=3 SCAR=24.8
Pod undocumented
113 0 my ( $self, $document_ids ) = @_;
114 0 ▶ return unless $document_ids;
Branch: 1 branch
BranchTrueFalseTotal
unless $document_ids 0 0 0
115  
116 0 $log->info( 'Deleting documents: ' . join( ', ', @$document_ids ) . '...' );
117 0 my %args = ( document_ids => $document_ids, );
118  
119 0 eval { $self->{api}->document_delete(%args); };
120 0 ▶ die $log->error(
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
121 sprintf(
122 "Failed to delete documents: %s.\nError:\n%s",
123 join( ', ', @$document_ids ),
124 format_error_message($@)
125 )
126 ) if $@;
127  
128 0 return;
129 }
130  
131 2 1;
« App/ProjectApi.pm ↑ Summary App/Command.pm »