Shell::Perl::Dumper - Dumpers for Shell::Perl
use Shell::Perl::Dumper; $dumper = Shell::Perl::Dumper::Plain->new; print $dumper->dump_scalar($scalar); print $dumper->dump_list(@list);
In pirl, the result of the evaluation is transformed into a string to be printed. As this result may be a pretty complex data structure, the shell provides a hook for you to pretty-print these answers just the way you want.
pirl
By default, pirl will try to convert the results via Data::Dump. That means the output will be Perl code that may be run to get the data structure again. Alternatively, the shell may use Data::Dumper or Data::Dump::Streamer with almost the same result with respect to the representation as Perl code. (But the output of the modules differ enough for sufficiently complex data.)
Data::Dump
Data::Dumper
Data::Dump::Streamer
Other options are to set the output to produce YAML or a plain simple-minded solution which basically turns the result to string via simple interpolation.
All of these are implemented via dumper objects. Dumpers are meant to be used like that:
$dumper = Some::Dumper::Class->new; # build a dumper $s = $dumper->dump_scalar($scalar); # from scalar to string $s = $dumper->dump_list(@list); # from list to string
The following methods compose the expected API of a dumper, as used by Shell::Perl.
$dumper = $class->new(@args);
Constructs a dumper.
$s = $dumper->dump_scalar($scalar);
Turns a scalar into a string representation.
$s = $dumper->dump_list(@list);
Turns a list into a string representation.
$ok = $class->is_available
This is an optional class method. If it exists, it means that the class has external dependencies (like Shell::Perl::Data::Dump depends on Data::Dump) and whether these may be loaded when needed. If they can, this method returns true. Otherwise, returning false means that a dumper instance of this class probably cannot work. This is typically because the dependency is not installed or cannot be loaded due to an installation problem.
Shell::Perl::Data::Dump
This is the algorithm used by Shell::Perl XXX XXX XXX
1.
Shell::Perl provides four standard dumpers:
* Shell::Perl::Data::Dump * Shell::Perl::Data::Dumper * Shell::Perl::Data::Dump::Streamer * Shell::Perl::Dumper::YAML * Shell::Perl::Dumper::Plain
which corresponds to the four options of the command :set out : "D", "DD", "DDS", "Y", and "P" respectively.
:set out
The package Shell::Perl::Data::Dump implements a dumper which uses Data::Dump to turn Perl variables into a string representation.
It is used like this:
use Shell::Perl::Dumper; if (!Shell::Perl::Data::Dump->is_available) { die "the dumper cannot be loaded correctly" } $dumper = Shell::Perl::Data::Dump->new; print $dumper->dump_scalar($scalar); print $dumper->dump_list(@list);
Examples of its output:
pirl > :set out D pirl > { a => 3 } #scalar { a => 3 } pirl > (1, 2, "a") #list (1, 2, "a")
The package Shell::Perl::Data::Dumper implements a dumper which uses Data::Dumper to turn Perl variables into a string representation.
Shell::Perl::Data::Dumper
use Shell::Perl::Dumper; if (!Shell::Perl::Data::Dumper->is_available) { die "the dumper cannot be loaded correctly" } $dumper = Shell::Perl::Data::Dumper->new; print $dumper->dump_scalar($scalar); print $dumper->dump_list(@list);
pirl > :set out DD pirl > { a => 3 } #scalar @var = ( { 'a' => 3 } ); pirl > (1, 2, "a") #list @var = ( 1, 2, 'a' );
The package Shell::Perl::Dumper::YAML implements a dumper which uses YAML::Syck or YAML to turn Perl variables into a string representation.
Shell::Perl::Dumper::YAML
use Shell::Perl::Dumper; if (!Shell::Perl::Dumper::YAML->is_available) { die "the dumper cannot be loaded correctly" } $dumper = Shell::Perl::Dumper::YAML->new; print $dumper->dump_scalar($scalar); print $dumper->dump_list(@list);
pirl > :set out Y pirl @> { a => 3 } #scalar --- a: 3 pirl @> (1, 2, "a") #list --- 1 --- 2 --- a
When loading, YAML::Syck is preferred to YAML. If it is not avaiable, the YAML module is the second option.
YAML::Syck
YAML
The documentation is yet to be written.
The package Shell::Perl::Dumper::Plain implements a dumper which uses string interpolation to turn Perl variables into strings.
Shell::Perl::Dumper::Plain
pirl > :set out P pirl > { a => 3 } #scalar HASH(0x1094d2c0) pirl > (1, 2, "a") #list 1 2 a
Shell::Perl
Please report bugs via CPAN RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Shell-Perl or mailto://bugs-Shell-Perl@rt.cpan.org.
Adriano R. Ferreira, <ferreira@cpan.org>
Caio Marcelo, <cmarcelo@gmail.com>
Copyright (C) 2007–2011 by Adriano R. Ferreira
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Shell::Perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Shell::Perl
CPAN shell
perl -MCPAN -e shell install Shell::Perl
For more information on module installation, please visit the detailed CPAN module installation guide.