File Coverage

lib/Serge/Sync/Plugin/TranslationService/phraseapp.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: PhraseApp (https://phraseapp.com) synchronization plugin for Serge
2              
3             package Serge::Sync::Plugin::TranslationService::phraseapp;
4 1     1   14914 use parent Serge::Sync::Plugin::Base::TranslationService, Serge::Interface::SysCmdRunner;
  1         3  
  1         8  
5              
6 1     1   1801 use strict;
  1         2  
  1         34  
7              
8 1     1   7 use Serge::Util qw(subst_macros);
  1         3  
  1         79  
9 1     1   447 use version;
  1         1901  
  1         5  
10              
11             our $VERSION = qv('0.901.0');
12              
13             sub name {
14 3     3 0 31647 return 'PhraseApp translation software (https://phraseapp.com) synchronization plugin';
15             }
16              
17             sub init {
18 3     3 0 39 my $self = shift;
19              
20 3         17 $self->SUPER::init(@_);
21              
22 3         22 $self->{optimizations} = 1; # set to undef to disable optimizations
23              
24 3         21 $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 2447 my ($self) = @_;
33              
34 3         17 $self->SUPER::validate_data;
35              
36 3         1650 $self->{data}->{config_file} = subst_macros($self->{data}->{config_file});
37 3         108 $self->{data}->{wait_for_uploads} = subst_macros($self->{data}->{wait_for_uploads});
38 3         84 $self->{data}->{verbose} = subst_macros($self->{data}->{verbose});
39              
40 3 50       80 die "'config_file' not defined" unless defined $self->{data}->{config_file};
41 3 100       30 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       66 $self->{data}->{wait_for_uploads} = 1 unless defined $self->{data}->{wait_for_uploads};
44 2 100       32 $self->{data}->{verbose} = 0 unless defined $self->{data}->{verbose};
45             }
46              
47             sub run_phraseapp_cli {
48 4     4 0 10 my ($self, $action, $langs, $capture) = @_;
49              
50 4         19 $ENV{'PHRASEAPP_CONFIG'} = $self->{data}->{config_file};
51              
52 4         50 my $command = $action;
53              
54 4         11 $command = 'phraseapp '.$command;
55              
56 4 100       13 if ($self->{data}->{verbose}) {
57 2         16 $command .= ' --verbose ';
58             }
59              
60 4         153 print "Running '$command'...\n";
61 4         48 return $self->run_cmd($command, $capture);
62             }
63              
64             sub pull_ts {
65 2     2 0 566 my ($self, $langs) = @_;
66              
67 2         10 return $self->run_phraseapp_cli('pull', $langs);
68             }
69              
70             sub push_ts {
71 2     2 0 1207 my ($self, $langs) = @_;
72              
73 2         6 my $action = 'push';
74              
75 2 100       11 if ($self->{data}->{wait_for_uploads}) {
76 1         11 $action = $action.' --wait';
77             }
78              
79 2         16 $self->run_phraseapp_cli($action, $langs);
80             }
81              
82             1;