App-dt

 view release on metacpan or  search on metacpan

script/dt  view on Meta::CPAN


our $DEBUG = $ENV{DEBUG};

sub _debug {
    my $msg = shift;

    $msg .= "\n" unless $msg =~ /\n$/;
    warn "DEBUG: $msg" if $DEBUG;
}

sub _guess_format_from_filename {
    my $filename = shift;

    # try to detect type from filename
    if ($filename =~ /\.(json|js)\z/i) {
        return 'json';
    } elsif ($filename =~ /\.(yaml|yml)\z/i) {
        return 'yaml';
    } elsif ($filename =~ /\.(perl|pl|pm|pod|dd)\z/i) {
        return 'perl';
    }

script/dt  view on Meta::CPAN

    my $fmt;
  DETERMINE_INPUT_FORMAT:
    {
        if ($filename eq '-') {
            $fmt = $Opts{default_input_format};
            last;
        } elsif ($filename =~ s/:(json|yaml|perl)\z//) {
            $fmt = $1;
            last;
        } else {
            $fmt = _guess_format_from_filename($filename);
            last if $fmt;
        }

        # XXX detect format by reading a few lines from it

        $fmt = $Opts{default_input_format};
    }
    _debug("input format=$fmt");

    my $fh;

script/dt  view on Meta::CPAN

  DETERMINE_OUTPUT_FORMAT:
    {
        if ($filename eq '-') {
            $fmt = $Opts{default_output_format};
            $pretty //= 1 if -t STDOUT;
            last;
        } elsif ($filename =~ s/:(json|yaml|perl)\z//) {
            $fmt = $1;
            last;
        } else {
            $fmt = _guess_format_from_filename($filename);
            last if $fmt;
        }

        $fmt = $Opts{default_output_format};
    }

    my $res;
    if ($fmt eq 'json') {
        if ($pretty) {
            require JSON::Color;

script/dt  view on Meta::CPAN


One or more C<--output> (C<-o>) options can be specified to direct output to
files. The first output file will be set to C<$DATA[0]> (or C<$DATA> or C<$_>),
the second to C<$DATA[1]> and so on. If no output files are specified, will
output to STDOUT.

=item * Convert JSON to YAML

 % dt books.json -o books.yaml

Input and output format are guessed from filename extension. Or, you can also
use C<:FORMAT> notation for input, e.g.:

 % dt books.dat:json -o books.yml

These formats are currently supported: C<json>, C<yaml>, C<perl>.

=item * Convert several JSON files to YAML

 % dt 1.json 2.json 3.json -o 1.yml -o 2.yml -o 3.yml

script/dt  view on Meta::CPAN

Set default output format. Default is C<json>. Can also be C<yaml>, C<perl>,
C<raw>.

=item * --default-output-format FORMAT, -F

Set default output format. Default is C<json>. Can also be C<yaml>, C<perl>,
C<raw>.

=item * --output FILENAME, -o

Add an output. Format will be guessed from .

If not specified, will output all data to STDOUT.

=back

=head1 ENVIRONMENT

=head2 DEBUG => bool

If set to true, print debugging messages.



( run in 0.654 second using v1.01-cache-2.11-cpan-702932259ff )