File::Dir::Dumper::App - a command line app-implemented as a class to do the


File-Dir-Dumper documentation Contained in the File-Dir-Dumper distribution.

Index


Code Index:

NAME

Top

File::Dir::Dumper::App - a command line app-implemented as a class to do the dumping.

VERSION

Top

Version 0.0.7

SYNOPSIS

Top

    use File::Dir::Dumper::App;

    my $app = File::Dir::Dumper::App->new({argv => \@ARGV});

    exit($app->run());

METHODS

Top

$self->new({ argv => \@ARGV})

Scans using the @ARGV command line arguments.

$self->run()

Runs the application.

AUTHOR

Top

Shlomi Fish, <shlomif@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-file-dir-dumper at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Dir-Dumper. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc File::Dir::Dumper




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Dir-Dumper

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/File-Dir-Dumper

* CPAN Ratings

http://cpanratings.perl.org/d/File-Dir-Dumper

* Search CPAN

http://search.cpan.org/dist/File-Dir-Dumper

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


File-Dir-Dumper documentation Contained in the File-Dir-Dumper distribution.
package File::Dir::Dumper::App;

use warnings;
use strict;

use base 'File::Dir::Dumper::Base';

use Carp;

use Getopt::Long qw(GetOptionsFromArray);
use Pod::Usage;

use File::Dir::Dumper::Scanner;
use File::Dir::Dumper::Stream::JSON::Writer;

__PACKAGE__->mk_accessors(
    qw(
    _out_to_stdout
    _out_filename
    _dir_to_dump
    )
);

our $VERSION = '0.0.7';

sub _init
{
    my $self = shift;
    my $args = shift;

    my $argv = $args->{'argv'};

    my $output_dest;

    my ($help, $man);

    GetOptionsFromArray($argv,
        "output|o=s" => \$output_dest,
        'help|h' => \$help,
        'man' => \$man,
    );

    pod2usage(1) if $help;
    pod2usage(-exitstatus => 0, -verbose => 2) if $man;    

    my $dir_to_dump = shift(@$argv);

    if (defined($output_dest))
    {
        $self->_out_to_stdout(0);
        $self->_out_filename($output_dest);
    }
    else
    {
        $self->_out_to_stdout(1);
    }

    $self->_dir_to_dump($dir_to_dump);

    return;
}

sub run
{
    my $self = shift;

    my $out;
    if ($self->_out_to_stdout())
    {
        open $out, ">&STDOUT";
    }
    else
    {
        open $out, ">", $self->_out_filename();
    }

    my $scanner = File::Dir::Dumper::Scanner->new(
        {
            dir => $self->_dir_to_dump(),
        }
    );
    my $writer = File::Dir::Dumper::Stream::JSON::Writer->new(
        {
            output => $out,
        }
    );

    while (defined(my $token = $scanner->fetch()))
    {
        $writer->put($token);
    }

    $writer->close();

    return 0;
}

1; # End of File::Dir::Dumper