Locale-Maketext-Lexicon

 view release on metacpan or  search on metacpan

lib/Locale/Maketext/Extract/Run.pm  view on Meta::CPAN

package Locale::Maketext::Extract::Run;
$Locale::Maketext::Extract::Run::VERSION = '1.00';
use strict;
use vars qw( @ISA @EXPORT_OK );
use File::Spec::Functions qw(catfile);

# ABSTRACT: Module interface to xgettext.pl


use Cwd;
use Config ();
use File::Find;
use Getopt::Long;
use Locale::Maketext::Extract;
use Exporter;

use constant HAS_SYMLINK => ( $Config::Config{d_symlink} ? 1 : 0 );

@ISA       = 'Exporter';
@EXPORT_OK = 'xgettext';

sub xgettext { __PACKAGE__->run(@_) }

sub run {
    my $self = shift;
    local @ARGV = @_;

    my %opts;
    Getopt::Long::Configure("no_ignore_case");
    Getopt::Long::GetOptions(
        \%opts,               'f|files-from:s@',
        'D|directory:s@',     'u|use-gettext-style|unescaped',
        'g|gnu-gettext',      'o|output:s@',
        'd|default-domain:s', 'p|output-dir:s@',
        'P|plugin:s@',        'W|wrap!',
        'w|warnings!',        'v|verbose+',
        'h|help',
    ) or help();

    help() if $opts{h};

    my %extract_options = %{ $self->_parse_extract_options( \%opts ) };

    my @po = @{ $opts{o} || [ ( $opts{d} || 'messages' ) . '.po' ] };

    foreach my $file ( @{ $opts{f} || [] } ) {
        open FILE, $file or die "Cannot open $file: $!";
        while (<FILE>) {
            chomp;
            push @ARGV, $_ if -r and !-d;
        }
    }

    foreach my $dir ( @{ $opts{D} || [] } ) {
        File::Find::find(
            {   wanted => sub {
                    if (-d) {
                        $File::Find::prune
                            = /^(\.svn|blib|autogen|var|m4|local|CVS|\.git)$/;
                        return;
                    }

                    # Only extract from non-binary, normal files
                    return unless ( -f or -s ) and -T;
                    return
                        if (/\.pot?$|\.bak$|~|,D|,B$/i)
                        || (/^[\.#]/);
                    push @ARGV, $File::Find::name;
                },
                follow => HAS_SYMLINK,
            },
            $dir
        );
    }

    @ARGV = ('-') unless @ARGV;
    s!^\.[/\\]!! for @ARGV;

    my $cwd = getcwd();

    my $Ext = Locale::Maketext::Extract->new(%extract_options);
    foreach my $dir ( @{ $opts{p} || ['.'] } ) {
        $Ext->extract_file($_) for grep !/\.po$/i, @ARGV;
        foreach my $po (@po) {
            $Ext->read_po($po) if -r $po and -s _;
            $Ext->compile( $opts{u} ) or next;



( run in 1.977 second using v1.01-cache-2.11-cpan-364913b4093 )