blib/script/embpmsgid.pl untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 120 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2015 Gerald Richter
6 # Embperl - Copyright (c) 2015-2023 actevy.io
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the Perl README file.
10 # For use with Apache httpd and mod_perl, see also Apache copyright.
11 #
12 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
13 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 #
16 ###################################################################################
17  
18  
19 BEGIN
20 {
21 %Embperl::initparam = (use_env => 1, use_redirect_env => 1) ;
22 $ENV{EMBPERL_SESSION_HANDLER_CLASS} = 'no' ;
23 }
24  
25 use Embperl;
26 use Data::Dumper ;
27 use Getopt::Long ;
28  
29  
30 if (!@ARGV)
31 {
32 print qq{
33 Extract message ids from Embperl files
34  
35 usage: $0 [options] [files]
36  
37 options:
38 --datadumper (-d) <file> Use the given file to read and
39 store message ids. Must be valid
40 Perl code which defines $msgids
41 --dbm (-b) <file> Use the given file to read and
42 store message ids. Must be a dbm
43 file.
44 --languages (-l) <code> Specify language code to generate
45 Can be given multiple times
46 } ;
47 exit (1) ;
48 } ;
49  
50  
51 my $ret = GetOptions ("datadumper|d=s", "dbm|b=s", 'languages|l=s@') ;
52  
53 exit (1) if (!$ret) ;
54  
55 if ($opt_datadumper && -f $opt_datadumper)
56 {
57 $msgids = do $opt_datadumper ;
58 die $@ if ($@) ;
59  
60 if (!ref $msgid eq 'HASH')
61 {
62 print SDTERR "File $opt_datadumper doesn't defines a hashref of message ids\n" ;
63 exit (1) ;
64 }
65  
66 }
67 elsif ($opt_dbm)
68 {
69 tie %msghash, 'DB_File', $opt_dbm, O_CREAT|O_RDWR or die "Cannot open $opt_dbm ($!)" ;
70
71 $msgids = \%msghash ;
72 }
73  
74 if (keys %$msgids)
75 {
76 print "Found languages: " ;
77 foreach (sort keys %$msgids)
78 {
79 print $_, ' ' ;
80 }
81 print "\n" ;
82 }
83  
84 if (@opt_languages)
85 {
86 print "Add languages: " ;
87 foreach (sort @opt_languages)
88 {
89 print $_, ' ' ;
90 $msgids -> {$_} ||= {} ;
91 }
92 print "\n" ;
93 }
94 elsif (!keys %$msgids)
95 {
96 $msgids -> {'en'} = {} ;
97 }
98  
99  
100 foreach my $fn (@ARGV)
101 {
102 my $out ;
103 my @errors ;
104 Embperl::Execute ({use_env => 1, use_redirect_env => 1, syntax => 'MsgIdExtract',
105 inputfile => $fn,
106 output => \$out,
107 errors => \@errors}) ;
108 if (@errors)
109 {
110 print join ("\n", @errors) ;
111 last ;
112 }
113 }
114  
115  
116 $Data::Dumper::Sortkeys = \&{ sub {[ sort { $a cmp $b } keys %{$_[0]} ]} } ;
117  
118 print Data::Dumper -> Dump ([\%Embperl::Syntax::MsgIdExtract::Ids], ['msgids']) ;
119  
120 if ($opt_datadumper || $opt_dbm)
121 {
122 if (keys %$msgids)
123 {
124 foreach my $lang (sort keys %$msgids)
125 {
126 foreach my $k (keys %Embperl::Syntax::MsgIdExtract::Ids)
127 {
128 $msgids -> {$lang}{$k} = '' if (!exists $msgids -> {$lang}{$k}) ;
129 }
130 }
131 }
132  
133 if ($opt_datadumper)
134 {
135 rename $opt_datadumper, "$opt_datadumper.bak" ;
136 open FH, ">$opt_datadumper" or die "Cannot open $opt_datadumper ($!)" ;
137 $Data::Dumper::Indent = 1 ;
138 #$Data::Dumper::Useqq = 1 ;
139 print FH Data::Dumper -> Dump ([$msgids], ['msgids']) ;
140 close FH ;
141 }
142 }
143  
144  
145 __END__