App-DataSectionSeekableUtils

 view release on metacpan or  search on metacpan

bin/dump-data-section-seekable  view on Meta::CPAN

#!perl

our $DATE = '2016-01-18'; # DATE
our $VERSION = '0.02'; # VERSION

use 5.010001;
use strict;
use warnings;

use Perinci::CmdLine::Any;

our %SPEC;

$SPEC{dump_data_section_seekable} = {
    v => 1.1,
    summary => 'Dump Data::Section::Seekable structure in a Perl file or module',
    args_rels => {
        req_one => [qw/file module/],
    },
    args => {
        file => {
            schema=>'str*',
            'x.schema.entity' => 'filename',
            pos => 0,
        },
        module => {
            schema=>'str*',
            'x.schema.entity' => 'modulename',
        },
    },
};
sub dump_data_section_seekable {
    my %args = @_;

    my $path;
    if ($args{module}) {
        require Module::Path::More;
        $path = Module::Path::More::module_path(module => $args{module})
            or return [404, "No such module"];
    } else {
        $path = $args{file};
    }

    (-f $path) or return [404, "No such file"];
    open my($fh), "<", $path or return [500, "Can't open file '$path': $!"];

    my $found;
    while (<$fh>) {
        chomp;
        do {$found++; last} if /\A__DATA__\z/;
    }
    return [412, "No __DATA__ found in file"] unless $found;

    require Data::Section::Seekable::Reader;
    my $reader = Data::Section::Seekable::Reader->new(handle=>$fh);

    my @parts = $reader->parts;

    [200, "OK", {
        num_parts => ~~@parts,
        parts => [map {+{
            name => $_,
            content => $reader->read_part($_),
            extra => $reader->read_extra($_),
        }} @parts],
    }];
}

Perinci::CmdLine::Any->new(url => '/main/dump_data_section_seekable')->run;

# ABSTRACT: Dump Data::Section::Seekable structure in a Perl file or module
# PODNAME: dump-data-section-seekable

__END__

=pod

=encoding UTF-8

=head1 NAME

dump-data-section-seekable - Dump Data::Section::Seekable structure in a Perl file or module

=head1 VERSION

This document describes version 0.02 of dump-data-section-seekable (from Perl distribution App-DataSectionSeekableUtils), released on 2016-01-18.

=head1 SYNOPSIS

Usage:

 % dump-data-section-seekable [options] [file]

=head1 OPTIONS

C<*> marks required options.

=head2 Configuration options

=over

=item B<--config-path>=I<filename>

Set path to configuration file.



( run in 2.269 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )