transerialize - transerialize files from a format to a different one
version 1.5.1
# simple $ transerialize foo.yaml bar.json # with options $ transerialize pretty=1 foo.yaml bar.json # reading from STDIN $ cat foo.yaml | transerialize -.yaml bar.json # printing to STDOUT $ transerialize foo.yaml -.json
transerialize is a command-line interface to the File::Serialize function of the same name.
transerialize
The command behaves pretty much like its underlying function, except for the details below.
All leading arguments containing an '=' will be considered default options. In other words,
$ transerialize pretty=1 format=json foo bar
is equivalent to the script
use File::Serialize { pretty => 1, format => 'json' }; transerialize_file 'foo' => 'bar';
Any argument that begin with a '{', '[' or 'sub {' will be eval'ed (as opposed as being considered filenames).
Any intermediary step that doesn't look like code (as specified in the previous section) is doing to be interpreted as a Perl script returning a transformation function.
For example, you could grab the title of a blog entry and put it in the frontmatter via:
$ transerialize ./README.md ./set_front_title.pl -.json
with ./set_front_title.pl looking like:
sub { return $_ if $_->{title}; $_->{title} = $1 if $_->{_content} =~ /^# (.*)/m; return $_; }
Any of the argument passed to transerialize that has a leading @ is considered a serialized file containing a list of files and will be expanded. Useful if you do have a lot of intermediary steps and the command line is getting ungainly long.
@
For example, you could have
# file ./process_blog.yml - set_front_title.pl - gather_tags.pl $ transerialize README.md @./process_blog.pl -.json
An input filename which main part is a dash will be taken to be STDIN. For example
$ transerialize_file -.yaml foo.json
will read STDIN, consider it to be YAML, and then convert it to JSON.
Likewise, an output file which main part is a dash will be printed on STDOUT. For example
$ transerialize_file foo.yaml -.json
will print out the data of foo.yaml as JSON.
The original source and destination files are available to transformation scripts via the global variables $File::Serialize::SOURCE and $File::Serialize::DESTINATION.
$File::Serialize::SOURCE
$File::Serialize::DESTINATION
Yanick Champoux <yanick@cpan.org>
This software is copyright (c) 2021, 2019, 2017, 2016, 2015 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install File::Serialize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Serialize
CPAN shell
perl -MCPAN -e shell install File::Serialize
For more information on module installation, please visit the detailed CPAN module installation guide.