| 1 | |||||||||||||||||||||||||||||
| 2 | =begin comment | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | Smartcat App | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | A simple command line application which allows to sync local files and Smartcat project content. | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =end comment | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =cut | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | package Smartcat::App; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use App::Cmd::Setup -app; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Class::Load; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use File::Copy qw/copy/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use IO::Uncompress::Unzip qw($UnzipError); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use JSON qw/encode_json/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Smartcat::Client::ProjectApi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Smartcat::Client::DocumentApi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Smartcat::Client::DocumentExportApi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use Smartcat::Client::Object::BilingualFileImportSetingsModel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use Smartcat::Client::Object::CreateDocumentPropertyModel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use Smartcat::Client::Object::UploadDocumentPropertiesModel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use Smartcat::App::ProjectApi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Smartcat::App::DocumentApi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use Smartcat::App::DocumentExportApi; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use Smartcat::App::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use Log::Any qw($log); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use Log::Any::Adapter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | our $VERSION = '0.0.12'; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | my $base_url = undef; | |||||||||||||||||||||||||||
| 49 | 2 | ▶ | $base_url = $self->{config}->base_url if ($self->{config}->base_url && $self->{config}->base_url ne ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"config"}->base_url and $self->{"config"}->base_url ne ""
MC/DC0%0/2
$self->{"config"}->base_url and $self->{"config"}->base_url ne ""
$self->{"config"}->base_url
$self->{"config"}->base_url ne ""
Truth table33%1/3
A and B
A= $self->{"config"}->base_urlB= $self->{"config"}->base_url ne ""
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $self->{api} = Smartcat::Client::ApiClient->new( | ||||||||||||||||||||||||||||
| 52 | username => $self->{config}->username, | ||||||||||||||||||||||||||||
| 53 | password => $self->{config}->password, | ||||||||||||||||||||||||||||
| 54 | 2 | base_url => $base_url, | |||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | my $log_level = "INFO"; | |||||||||||||||||||||||||||
| 58 | 2 | ▶ | if ( defined $self->{rundata}->{debug} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | $log_level = "DEBUG"; | |||||||||||||||||||||||||||
| 60 | 1 | print "*** DEBUG mode is turned on ***\n"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | my $appender = ""; | |||||||||||||||||||||||||||
| 64 | 2 | my $filter = <<"EOT"; | |||||||||||||||||||||||||||
| 65 | log4perl.filter.MatchWarnInfoDebug = Log::Log4perl::Filter::LevelRange | ||||||||||||||||||||||||||||
| 66 | log4perl.filter.MatchWarnInfoDebug.LevelMin = DEBUG | ||||||||||||||||||||||||||||
| 67 | log4perl.filter.MatchWarnInfoDebug.LevelMax = WARN | ||||||||||||||||||||||||||||
| 68 | log4perl.appender.screen.Filter = MatchWarnInfoDebug | ||||||||||||||||||||||||||||
| 69 | EOT | ||||||||||||||||||||||||||||
| 70 | 2 | my $logger = ""; | |||||||||||||||||||||||||||
| 71 | 2 | ▶ | if ( defined $self->{config}->log && $self->{config}->log ne "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"config"}->log and $self->{"config"}->log ne ""
MC/DC0%0/2
defined $self->{"config"}->log and $self->{"config"}->log ne ""
defined $self->{"config"}->log
$self->{"config"}->log ne ""
Truth table33%1/3
A and B
A= defined $self->{"config"}->logB= $self->{"config"}->log ne ""
| |||||||||||||||||||||||||||||
| 72 | 2 | print "*** Printing to '$self->{config}->{log}' log file ***\n"; | |||||||||||||||||||||||||||
| 73 | 2 | $logger = ", file"; | |||||||||||||||||||||||||||
| 74 | 2 | $appender = <<"EOT"; | |||||||||||||||||||||||||||
| 75 | log4perl.appender.file = Log::Log4perl::Appender::File | ||||||||||||||||||||||||||||
| 76 | log4perl.appender.file.filename = $self->{config}->{log} | ||||||||||||||||||||||||||||
| 77 | log4perl.appender.file.mode = append | ||||||||||||||||||||||||||||
| 78 | log4perl.appender.file.layout = PatternLayout | ||||||||||||||||||||||||||||
| 79 | log4perl.appender.file.layout.ConversionPattern = [%d] %p> %m%n | ||||||||||||||||||||||||||||
| 80 | EOT | ||||||||||||||||||||||||||||
| 81 | 2 | $filter = <<"EOT"; | |||||||||||||||||||||||||||
| 82 | log4perl.filter.MatchWarnInfo = Log::Log4perl::Filter::LevelRange | ||||||||||||||||||||||||||||
| 83 | log4perl.filter.MatchWarnInfo.LevelMin = INFO | ||||||||||||||||||||||||||||
| 84 | log4perl.filter.MatchWarnInfo.LevelMax = WARN | ||||||||||||||||||||||||||||
| 85 | log4perl.appender.screen.Filter = MatchWarnInfo | ||||||||||||||||||||||||||||
| 86 | EOT | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | Log::Log4perl->init( \ <<"EOT"); | |||||||||||||||||||||||||||
| 91 | log4perl.logger = $log_level, screen $logger | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | log4perl.appender.screen = Log::Log4perl::Appender::Screen | ||||||||||||||||||||||||||||
| 94 | log4perl.appender.screen.stderr = 0 | ||||||||||||||||||||||||||||
| 95 | log4perl.appender.screen.layout = PatternLayout | ||||||||||||||||||||||||||||
| 96 | log4perl.appender.screen.layout.ConversionPattern = %m%n | ||||||||||||||||||||||||||||
| 97 | $filter | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | $appender | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | EOT | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | Log::Any::Adapter->set('Log::Log4perl'); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 4 | my ( $class, $arg ) = @_; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 4 | my $self = $class->SUPER::new($arg); | |||||||||||||||||||||||||||
| 110 | 4 | $self->{config} = Smartcat::App::Config->load; | |||||||||||||||||||||||||||
| 111 | 4 | $self->{rundata} = {}; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 4 | return $self; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub project_api { | ||||||||||||||||||||||||||
|
Subroutine
project_api: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 117 | 4 | my $self = shift @_; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | $self->{project_api} = | ||||||||||||||||||||||||||||
| 120 | Smartcat::App::ProjectApi->new( $self->{api}, $self->{rundata} ) | ||||||||||||||||||||||||||||
| 121 | 4 | ▶ | unless defined $self->{project_api}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 4 | return $self->{project_api}; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub document_api { | ||||||||||||||||||||||||||
|
Subroutine
document_api: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 2 | my $self = shift @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | $self->{document_api} = | ||||||||||||||||||||||||||||
| 129 | Smartcat::App::DocumentApi->new( $self->{api}, $self->{rundata} ) | ||||||||||||||||||||||||||||
| 130 | 2 | ▶ | unless defined $self->{document_api}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 2 | return $self->{document_api}; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | ▶ | sub document_export_api { | ||||||||||||||||||||||||||
|
Subroutine
document_export_api: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 2 | my $self = shift @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | $self->{document_export_api} = | ||||||||||||||||||||||||||||
| 138 | Smartcat::App::DocumentExportApi->new( $self->{api}, $self->{rundata} ) | ||||||||||||||||||||||||||||
| 139 | 2 | ▶ | unless defined $self->{document_export_api}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 2 | return $self->{document_export_api}; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 2 | 1; | |||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||