The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl

our $DATE = '2017-05-23'; # DATE
our $VERSION = '0.13'; # VERSION

use 5.010001;
use strict;
use warnings;

my ($from, $to) = $0 =~ /(\w+)2(\w+)\z/
    or die "Can't determine what formats to convert from/to, ".
    "please call me as one of dd2json, json2dd, etc.\n";

undef $/;

my $code_from;
if ($from eq 'dd') {
    $code_from = 'eval ~~<>';
} elsif ($from eq 'ddc') {
    $code_from = 'eval ~~<>';
} elsif ($from eq 'json') {
    require JSON::MaybeXS;
    $code_from = 'JSON::MaybeXS->new->allow_nonref->decode(~~<>)';
} elsif ($from eq 'phpser') {
    require PHP::Serialization;
    $code_from = 'PHP::Serialization::unserialize(~~<>)';
} elsif ($from eq 'sereal') {
    require Sereal::Decoder;
    $code_from = 'Sereal::Decoder::decode_sereal(~~<>)';
} elsif ($from eq 'storable') {
    require Storable;
    $code_from = 'Storable::thaw(~~<>)';
} elsif ($from eq 'yaml') {
    no warnings 'once';
    require YAML::Syck; $YAML::Syck::ImplicitTyping = 1;
    $code_from = 'YAML::Syck::Load(~~<>)';
} else {
    die "Can't convert from '$from'";
}

my $code_to;
if ($to eq 'dd') {
    require Data::Dump;
    $code_to = "Data::Dump::dump($code_from)";
} elsif ($to eq 'ddc') {
    require Data::Dump::Color;
    $code_to = "Data::Dump::Color::dump($code_from)";
} elsif ($to eq 'json') {
    require JSON::MaybeXS;
    $code_to = "JSON::MaybeXS->new->allow_nonref->encode($code_from)";
} elsif ($to eq 'phpser') {
    require PHP::Serialization;
    $code_to = "PHP::Serialization::serialize($code_from)";
} elsif ($to eq 'sereal') {
    require Sereal::Encoder;
    $code_to = "Sereal::Encoder::encode_sereal($code_from)";
} elsif ($to eq 'storable') {
    require Storable;
    $code_to = "Storable::freeze($code_from)";
} elsif ($to eq 'yaml') {
    no warnings 'once';
    require YAML::Syck; $YAML::Syck::ImplicitTyping = 1;
    $code_to = "YAML::Syck::Dump($code_from)";
} else {
    die "Can't convert to '$to'";
}

eval "print $code_to";
die if $@;

1;
# ABSTRACT: Convert between serialization formats
# PODNAME: phpser2yaml

__END__

=pod

=encoding UTF-8

=head1 NAME

phpser2yaml - Convert between serialization formats

=head1 VERSION

This document describes version 0.13 of phpser2yaml (from Perl distribution App-SerializeUtils), released on 2017-05-23.

=head1 SYNOPSIS

This script can be called as various names to convert between serialization
formats (note: dd is Perl format using Data::Dump, ddc is Perl format using
Data::Dump::Color):

 dd2ddc
 dd2json
 dd2phpser
 dd2sereal
 dd2storable
 dd2yaml

 json2dd
 json2ddc
 json2phpser
 json2sereal
 json2storable
 json2yaml

 phpser2dd
 phpser2ddc
 phpser2json
 phpser2sereal
 phpser2storable
 phpser2yaml

 sereal2dd
 sereal2ddc
 sereal2json
 sereal2phpser
 sereal2storable
 sereal2yaml

 storable2dd
 storable2ddc
 storable2json
 storable2phpser
 storable2sereal
 storable2yaml

 yaml2dd
 yaml2ddc
 yaml2json
 yaml2phpser
 yaml2sereal
 yaml2storable

=head1 DESCRIPTION

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-SerializeUtils>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-SerializeUtils>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-SerializeUtils>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 SEE ALSO

L<App::SerializeUtils>

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017, 2015, 2014, 2013, 2011 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut