Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
Adding the as_* methods as requested in evalEmpire#230
Browse files Browse the repository at this point in the history
NOTES/POSSIBLE ISSUES:
  - the test is calling ::2 directly rather then latest.
    I was unsure on the going convention for a version specific change
  - I am not using alias to build the aliases.
    It seemed a bit heavy handed so I am using the old-style delegation.
  • Loading branch information
ben hengst committed Mar 5, 2013
1 parent e9b64a9 commit 89e8a05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/perl5i/2/Meta/Instance.pm
Expand Up @@ -138,7 +138,7 @@ sub is_equal {
return perl5i::2::equal::are_equal($$$self, $other); return perl5i::2::equal::are_equal($$$self, $other);
} }



sub as_perl{shift->perl(@_)}
sub perl { sub perl {
require Data::Dumper; require Data::Dumper;


Expand Down Expand Up @@ -173,7 +173,7 @@ sub dump {
return $self->$dumper(%args); return $self->$dumper(%args);
} }



sub as_json { shift->_dump_as_json(@_)}
sub _dump_as_json { sub _dump_as_json {
require JSON; require JSON;
my $json = JSON->new my $json = JSON->new
Expand All @@ -198,6 +198,7 @@ sub _dump_as_json {
return $json->encode(${${$_[0]}}); return $json->encode(${${$_[0]}});
} }


sub as_yaml { shift->_dump_as_yaml(@_)}
sub _dump_as_yaml { sub _dump_as_yaml {
require YAML::Any; require YAML::Any;
return YAML::Any::Dump(${${$_[0]}}); return YAML::Any::Dump(${${$_[0]}});
Expand Down
11 changes: 11 additions & 0 deletions t/dump/formats.t
@@ -0,0 +1,11 @@
#!perl -w

use perl5i::2; # I did not see any testing README for how to introduce a
# version specific change? Is everything expected to be latest?
use Test::More tests => 3;

my $ref = [1..10];

is_deeply $ref->mo->as_perl, $ref->mo->perl, 'perl';
is_deeply $ref->mo->as_json, $ref->mo->dump(format=>'json'), 'json';
is_deeply $ref->mo->as_yaml, $ref->mo->dump(format=>'yaml'), 'yaml';

0 comments on commit 89e8a05

Please sign in to comment.