| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of Dist-Zilla-App-Command-pot | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2011 by Jerome Quelin. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use 5.012; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | package Dist::Zilla::App::Command::pot; | ||||||||||||||||||||||||||||
| 14 | # ABSTRACT: update i18n messages.pot file with new strings | ||||||||||||||||||||||||||||
| 15 | 1 | $Dist::Zilla::App::Command::pot::VERSION = '2.000'; | |||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Dist::Zilla::App -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Temp qw{ tempfile }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use IO::Prompt; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Moose::Autobox; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Path::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | "Update the messages.pot file with new i18n strings found in the | |||||||||||||||||||||||||||
| 24 | distribution modules."; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | return ( | ||||||||||||||||||||||||||||
| 31 | 0 | [], | |||||||||||||||||||||||||||
| 32 | [ "output|o=s", "location of the messages.pot to update" ], | ||||||||||||||||||||||||||||
| 33 | [ "input|i=s@", "input file(s) (defaults to all .pm files)" ], | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $opts, $args) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $zilla = $self->zilla; | |||||||||||||||||||||||||||
| 41 | 0 | $zilla->build; | |||||||||||||||||||||||||||
| 42 | 0 | my $dist = $self->zilla->distmeta->{name}; | |||||||||||||||||||||||||||
| 43 | 0 | my $copy = $self->zilla->distmeta->{author}->[0]; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # build list of perl modules from where to extract strings | ||||||||||||||||||||||||||||
| 46 | my @pmfiles = | ||||||||||||||||||||||||||||
| 47 | 0 | grep { $_->name =~ /\.pm$/ } | |||||||||||||||||||||||||||
| 48 | 0 | grep { $_->isa( "Dist::Zilla::File::OnDisk" ) } | |||||||||||||||||||||||||||
| 49 | $zilla->files->flatten; | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | @pmfiles = $self->_filter_input_files($opts->{input}, @pmfiles); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $tmp = File::Temp->new( UNLINK=>1 ); | |||||||||||||||||||||||||||
| 54 | 0 | $tmp->print( map { $_->name . "\n" } @pmfiles ); | |||||||||||||||||||||||||||
| 55 | 0 | $tmp->close; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # no messages.pot found, prompting user | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( not defined $opts->{output} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | # try to find existing messages.pot | ||||||||||||||||||||||||||||
| 60 | 0 | $zilla->log( "Trying to find a messages.pot file..."); | |||||||||||||||||||||||||||
| 61 | ($opts->{output}) = | ||||||||||||||||||||||||||||
| 62 | 0 | map { $_->name } | |||||||||||||||||||||||||||
| 63 | 0 | grep { $_->name =~ /messages\.pot$/ } | |||||||||||||||||||||||||||
| 64 | 0 | grep { $_->isa( "Dist::Zilla::File::OnDisk" ) } | |||||||||||||||||||||||||||
| 65 | $zilla->files->flatten; | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( defined $opts->{output} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $zilla->log( "Found [$opts->{output}]" ); | |||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||
| 69 | 0 | $zilla->log( "No messages.pot found - enter your own." ); | |||||||||||||||||||||||||||
| 70 | 0 | my $default = "lib/LocaleData/$dist-messages.pot"; | |||||||||||||||||||||||||||
| 71 | 0 | $opts->{output} = prompt( "messages.pot to use: ", -d => $default ); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # update pot file | ||||||||||||||||||||||||||||
| 76 | 0 | unlink $opts->{output}; | |||||||||||||||||||||||||||
| 77 | 0 | file($opts->{output})->parent->mkpath; | |||||||||||||||||||||||||||
| 78 | 0 | $zilla->log( "Running xgettext..." ); | |||||||||||||||||||||||||||
| 79 | system( | ||||||||||||||||||||||||||||
| 80 | "xgettext", | ||||||||||||||||||||||||||||
| 81 | "--keyword=T", | ||||||||||||||||||||||||||||
| 82 | "--keyword=__", | ||||||||||||||||||||||||||||
| 83 | "--from-code=utf-8", | ||||||||||||||||||||||||||||
| 84 | "--package-name=$dist", | ||||||||||||||||||||||||||||
| 85 | "--copyright-holder='$copy'", | ||||||||||||||||||||||||||||
| 86 | "-o", $opts->{output}, | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | "-f", $tmp | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | ) == 0 or die "xgettext exited with return code " . ($? >> 8); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub _filter_input_files { | ||||||||||||||||||||||||||
|
Subroutine
_filter_input_files: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 92 | 0 | my ($self, $input, @pmfiles) = @_; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return @pmfiles unless $input && @$input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$input and @$input
MC/DC0%0/2
$input and @$input
$input
@$input
Truth table0%0/3
A and B
A= $inputB= @$input
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my %filter = map { ($_ => 1) } @$input; | |||||||||||||||||||||||||||
| 97 | 0 | return grep { $filter{ $_->_original_name } } @pmfiles; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||