Acme-Nyaa

 view release on metacpan or  search on metacpan

bin/nyaa  view on Meta::CPAN

#!/usr/bin/env perl
# $Id: nyaa.PL,v 1.2 2011/02/11 10:20:26 ak Exp $
use strict;
use warnings;
use utf8;
use Acme::Nyaa;
use IO::File;
use Encode;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
use File::Basename qw(basename);

BEGIN {
    my $modulelist = [ 'Acme::Nyaa' ];

    if( defined $ARGV[0] ) {

        if( $ARGV[0] eq '--modules' ) {

            print $_.qq(\n) for @$modulelist;
            exit 0;
        }
    }
}

my $Version = $Acme::Nyaa::VERSION;
my $CatConf = { 'language' => 'ja' };
my $Options = {
    'nyaa' => ( 1 << 0 ),
    'noun' => ( 1 << 1 ),
    #'lang' => ( 1 << 2 ),
    #'test' => ( 1 << 3 ),
};
my $RunMode = parseoptions();

if( $RunMode ) {

    my $inputfiles = \@ARGV || [];
    my $filehandle = undef;
    my $nekonyaaaa = Acme::Nyaa->new( %$CatConf );
    my $nekobuffer = q();
    my $nounoption = $RunMode & $Options->{'noun'};

    push @$inputfiles, \*STDIN unless scalar @$inputfiles;

    foreach my $e ( @$inputfiles ) {

        $filehandle = ref $e ? $e : IO::File->new( $e, 'r' ) or die 'Cannot open '.$e;
        $nekobuffer = [ <$filehandle> ];
        print $nekonyaaaa->straycat( $nekobuffer, $nounoption );
    }
}

sub parseoptions {

    my $o = 0;
    my $opt_nyaa;
    my $opt_noun;
    #my $opt_lang;

    Getopt::Long::Configure( qw/posix_default no_ignore_case gnu_compat/ );
    Getopt::Long::GetOptions(
        'n'         => \$opt_noun,
        'noun'      => \$opt_noun,
    #   'L=s'       => \$opt_lang,
    #   'lang=s'    => \$opt_lang,



( run in 0.841 second using v1.01-cache-2.11-cpan-98e64b0badf )