| 1 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 22 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package Locale::Simple::Scraper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 22 | our $VERSION = '0.200'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: scraper to find translation tokens in a directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 22 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 22 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 22 | ▶ | use Locale::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 22 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 22 | ▶ | use Locale::Simple::Scraper::Parser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 22 | our @EXPORT = qw(scrape); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 22 | my %OUTPUT_FORMATS = map { $_ => 1 } qw( po perl json yaml ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 22 | my $USAGE = <<'END'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Usage: locale-simple scrape [OPTIONS] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | Walks the current directory and writes a .pot template to STDOUT; progress and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | parse problems go to STDERR. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | --js EXT --pl EXT --py EXT --php EXT --go EXT --rs EXT --tx EXT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | extra file extensions for a language, comma-separated, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | repeatable (defaults: js; pl pm t; py; php; go; rs; tx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | --ignore REGEX skip files whose path matches, repeatable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | --only REGEX read only files whose path matches, repeatable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | --output FORMAT po (default), perl, json or yaml (yaml needs the YAML module) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | --md5 write MD5 hashes of the file names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | --no_line_numbers leave out the #: location comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | -h, --help show this text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | END | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | sub usage { return $USAGE } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | sub _bad_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bad_call: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | my ($message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | $message .= "\n" unless $message =~ /\n\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | die bless { message => $message }, 'Locale::Simple::Scraper::BadCall'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 70 | ▶ | sub scrape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scrape: called CC=28 SCAR=33.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 70 | @ARGV = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 70 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Supported filetypes and the extensions read as them. --js, --pl, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # add more: repeatable, each a comma-separated list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 70 | my %defaults = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | js => ['js'], # Javascript | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | pl => [ 'pl', 'pm', 't' ], # Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | tx => ['tx'], # Text::Xslate (Kolon or Metakolon) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | py => ['py'], # Python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | php => ['php'], # PHP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | go => ['go'], # Go | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | rs => ['rs'], # Rust | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 70 | my @types = qw( js pl tx py php go rs ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 70 | my %extra = map { $_ => [] } @types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 70 | my @ignores; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | my @only; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 70 | my $output = 'po'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 70 | my ($md5, $no_line_numbers, $help); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 70 | my @problems; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 70 | my $parsed = do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 70 | ▶ | local $SIG{__WARN__} = sub { push @problems, @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 70 | ( map { ( "$_=s" => $extra{$_} ) } @types ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | "ignore=s" => \@ignores, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | "only=s" => \@only, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | "output=s" => \$output, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | "md5" => \$md5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | "no_line_numbers" => \$no_line_numbers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | "help|h" => \$help, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 70 | ▶ | _bad_call( join '', @problems ) unless $parsed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 67 | ▶ | if ($help) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | print STDOUT $USAGE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 61 | ▶ | _bad_call("Unexpected argument: $ARGV[0]") if @ARGV; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | _bad_call("Unknown output format: $output (use po, perl, json or yaml)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 60 | ▶ | unless $OUTPUT_FORMATS{$output}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # extension list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 58 | my %e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 58 | for my $type ( @types ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 406 | $e{$_} = $type for ( map { split /,/ } @{ $extra{$type} } ), @{ $defaults{$type} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # functions with count of locale simple with function of parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # 1 = msgid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # 2 = msgid_plural | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # 3 = msgctxt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # 4 = domain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 58 | my %f = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | l => [1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ln => [ 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ld => [ 4, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | lp => [ 3, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | lnp => [ 3, 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ldn => [ 4, 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ldp => [ 4, 3, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ldnp => [ 4, 3, 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Deferred-translation markers (see DEFERRED TRANSLATION in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Locale::Simple). Same mapping as their l* twins — identical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # .pot output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | N_ => [1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | Nn_ => [ 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Nd_ => [ 4, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | Np_ => [ 3, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | Nnp_ => [ 3, 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | Ndn_ => [ 4, 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Ndp_ => [ 4, 3, 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Ndnp_ => [ 4, 3, 1, 2 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 58 | my %files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 58 | my $dir = getcwd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | finddepth( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 14975 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 14975 | my $filename = $File::Find::name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 14975 | $filename =~ s/^\Q$dir\E\///; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 14975 | my $stored_filename = $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 14975 | ▶ | if ( $md5 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | require Digest::MD5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | Digest::MD5->import( 'md5_hex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | ▶ | die "This feature requires Digest::MD5" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 6 | $stored_filename = md5_hex( $filename ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 14975 | for ( @ignores ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 19758 | ▶ | return if $filename =~ /$_/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 14216 | ▶ | if ( @only ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 14025 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14025 | for ( @only ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 14025 | ▶ | $found = 1 if $filename =~ /$_/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 14025 | ▶ | return unless $found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 242 | my @fileparts = split( '\.', $File::Find::name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 242 | my $ext = pop @fileparts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 242 | ▶ | $files{$File::Find::name} = [ $ext, $filename, $stored_filename ] if grep { $ext eq $_ } keys %e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 58 | $dir | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 58 | my @found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 58 | for my $file ( sort keys %files ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 114 | my ( $ext, $filename, $stored_filename ) = @{ $files{$file} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 114 | my $type = $e{$ext}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 114 | print STDERR $type . " => " . $file . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 114 | ▶ | next if -l $file and not -e $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-l $file and not -e $file
MC/DC100%2/2
-l $file and not -e $file
-l $file
not -e $file
Truth table100%3/3
A and not(B)
A= -l $fileB= not -e $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 112 | my $parses = Locale::Simple::Scraper::Parser->new( type => $type )->from_file( $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | my @file_things = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 693 | %{ result_from_params( $_->{args}, $f{ $_->{func} } ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | line => $_->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 693 | file => $stored_filename, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 112 | } @{$parses}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 112 | push @found, @file_things; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 58 | ▶ | if ( $output eq 'po' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 24 | my %files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | my %token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 24 | for ( @found ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 412 | ▶ | my $key .= defined $_->{domain} ? '"' . $_->{domain} . '"' : 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 412 | ▶ | $key .= defined $_->{msgctxt} ? '"' . $_->{msgctxt} . '"' : 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 412 | ▶ | $key .= defined $_->{msgid} ? '"' . $_->{msgid} . '"' : 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 412 | ▶ | $key .= defined $_->{msgid_plural} ? '"' . $_->{msgid_plural} . '"' : 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 412 | ▶ | $token{$key} = $_ unless defined $token{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 412 | ▶ | $files{$key} = [] unless defined $files{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 412 | push @{ $files{$key} }, $_->{file} . ':' . $_->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 24 | for my $k ( sort { $a cmp $b } keys %files ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 289 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 289 | ▶ | print "#: " . join( ' ', @{ $files{$k} } ) . "\n" if !$no_line_numbers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 289 | print "#, locale-simple-format"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 289 | ▶ | print " " . $token{$k}{domain} if defined $token{$k}{domain}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 289 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 289 | for ( qw( msgctxt msgid msgid_plural ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | print $_. ' "' . Locale::Simple::gettext_escape( $token{$k}{$_} ) . '"' . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 867 | ▶ | if defined $token{$k}{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 289 | ▶ | my $plural_marker = $token{$k}{msgid_plural} ? "[0]" : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 289 | print qq[msgstr$plural_marker ""\n]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | elsif ( $output eq 'perl' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 30 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 30 | print Dumper \@found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | elsif ( $output eq 'json' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | require JSON::PP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | print JSON::PP->new->canonical->encode( \@found ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | elsif ( $output eq 'yaml' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | ▶ | eval { require YAML; 1 } or die "--output yaml needs the YAML module\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | print YAML::Dump( \@found ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub parse_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_line: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my ( $line, $type, $f, @results ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return if $line =~ /^\s*\#.*/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | for ( keys %{$f} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my @args = @{ $f->{$_} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $params = get_func_params( $_, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | next if !$params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $argc = scalar @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ( $remainder, @params ) = parse_params( $params, $type, $argc ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ( scalar @params == $argc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | push @results, result_from_params( \@params, \@args ), parse_line( $remainder, $type, $f ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return @results; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 693 | ▶ | sub result_from_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_from_params: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 693 | my ( $params, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 693 | my %result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 693 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 693 | for ( @{$args} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1350 | ▶ | $result{msgid} = $params->[$pos] if $_ eq 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1350 | ▶ | $result{msgid_plural} = $params->[$pos] if $_ eq 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1350 | ▶ | $result{msgctxt} = $params->[$pos] if $_ eq 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 1350 | ▶ | $result{domain} = $params->[$pos] if $_ eq 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1350 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 693 | return \%result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub get_func_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_func_params: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my ( $func, $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $line =~ /([^\w]|^)$func\((.*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub parse_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_params: not called CC=21 SCAR=61.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my ( $params, $type, $argc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my @chars = split( '', $params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my $arg = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $q_state = 0; # 0 = code, 1 = qoute, 2 = double qoute | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $comma_state = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | while ( defined( my $c = shift @chars ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | next if $c =~ /\s/ and !$q_state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c =~ /\s/ and not $q_state
MC/DC0%0/2
$c =~ /\s/ and not $q_state
$c =~ /\s/
not $q_state
Truth table0%0/3
A and not(B)
A= $c =~ /\s/B= not $q_state
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ( $q_state ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if ( $c eq '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $esc = shift @chars; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ( $esc eq "'" or $esc eq '"' or $esc eq '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$esc eq "'" or $esc eq "\"" or $esc eq "\\"
$esc eq "'" or $esc eq "\""
MC/DC0%0/3
$esc eq "'" or $esc eq "\"" or $esc eq "\\"
$esc eq "'"
$esc eq "\""
$esc eq "\\"
Truth table0%0/4
A or B or C
A= $esc eq "'"B= $esc eq "\""C= $esc eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $arg .= $esc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | warn "Unknown escape char '" . $esc . "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ▶ | elsif ( ( $c eq "'" and $q_state == 1 ) or ( $c eq '"' and $q_state == 2 ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$c eq "'" and $q_state == 1 or $c eq "\"" and $q_state == 2
$c eq "'" and $q_state == 1
$c eq "\"" and $q_state == 2
MC/DC0%0/4
$c eq "'" and $q_state == 1 or $c eq "\"" and $q_state == 2
$c eq "'"
$q_state == 1
$c eq "\""
$q_state == 2
Truth table0%0/7
A and B or C and D
A= $c eq "'"B= $q_state == 1C= $c eq "\""D= $q_state == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $q_state = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $comma_state = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | push @args, $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $arg = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | last if scalar @args == $argc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $arg .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ( $c eq "'" or $c eq '"' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$c eq "'" or $c eq "\""
MC/DC0%0/2
$c eq "'" or $c eq "\""
$c eq "'"
$c eq "\""
Truth table0%0/3
A or B
A= $c eq "'"B= $c eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | die "quote found where comma expected: " . $params unless $comma_state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | $q_state = $c eq "'" ? 1 : 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | elsif ( $c eq ',' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | die "comma found after comma in code: " . $params if $comma_state; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $comma_state = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | elsif ( $type eq 'js' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | return join( '', @chars ), @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 22 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||