File Coverage

lib/Serge/Sync/Plugin/TranslationService/phrase.pm
Criterion Covered Total %
statement 41 41 100.0
branch 11 12 91.6
condition n/a
subroutine 10 10 100.0
pod 0 6 0.0
total 62 69 89.8


line stmt bran cond sub pod time code
1             # ABSTRACT: Phrase (https://phrase.com) synchronization plugin for Serge
2              
3             package Serge::Sync::Plugin::TranslationService::phrase;
4 1     1   12313 use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner;
  1         2  
  1         5  
5              
6 1     1   1441 use strict;
  1         2  
  1         18  
7              
8 1     1   5 use Serge::Util qw(subst_macros);
  1         1  
  1         58  
9 1     1   362 use version;
  1         1576  
  1         5  
10              
11             our $VERSION = qv('0.904.0');
12              
13             sub name {
14 3     3 0 27415 return 'Phrase translation software (https://phrase.com) synchronization plugin';
15             }
16              
17             sub init {
18 3     3 0 31 my $self = shift;
19              
20 3         12 $self->SUPER::init(@_);
21              
22 3         16 $self->{optimizations} = 1; # set to undef to disable optimizations
23              
24 3         15 $self->merge_schema({
25             config_file => 'STRING',
26             wait_for_uploads => 'BOOLEAN',
27             verbose => 'BOOLEAN'
28             });
29             }
30              
31             sub validate_data {
32 3     3 0 1894 my ($self) = @_;
33              
34 3         13 $self->SUPER::validate_data;
35              
36 3         1049 $self->{data}->{config_file} = subst_macros($self->{data}->{config_file});
37 3         78 $self->{data}->{wait_for_uploads} = subst_macros($self->{data}->{wait_for_uploads});
38 3         66 $self->{data}->{verbose} = subst_macros($self->{data}->{verbose});
39              
40 3 50       64 die "'config_file' not defined" unless defined $self->{data}->{config_file};
41 3 100       23 die "'config_file', which is set to '$self->{data}->{config_file}', does not point to a valid file.\n" unless -f $self->{data}->{config_file};
42              
43 2 100       52 $self->{data}->{wait_for_uploads} = 1 unless defined $self->{data}->{wait_for_uploads};
44 2 100       24 $self->{data}->{verbose} = 0 unless defined $self->{data}->{verbose};
45             }
46              
47             sub run_phrase_cli {
48 4     4 0 10 my ($self, $action, $langs, $capture) = @_;
49              
50 4         12 local $ENV{'PHRASEAPP_CONFIG'} = $self->{data}->{config_file};
51              
52 4         43 my $command = $action;
53              
54 4         9 $command = 'phrase '.$command;
55              
56 4 100       11 if ($self->{data}->{verbose}) {
57 2         13 $command .= ' --verbose ';
58             }
59              
60 4         125 print "Running '$command'...\n";
61 4         33 return $self->run_cmd($command, $capture);
62             }
63              
64             sub pull_ts {
65 2     2 0 539 my ($self, $langs) = @_;
66              
67 2         6 return $self->run_phrase_cli('pull', $langs);
68             }
69              
70             sub push_ts {
71 2     2 0 1211 my ($self, $langs) = @_;
72              
73 2         4 my $action = 'push';
74              
75 2 100       9 if ($self->{data}->{wait_for_uploads}) {
76 1         9 $action = $action.' --wait';
77             }
78              
79 2         12 $self->run_phrase_cli($action, $langs);
80             }
81              
82             1;