Permalink
Browse files

Adding the as_* methods as requested in #230

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...
1 parent e9b64a9 commit 89e8a05e807a1d99286633d6e3dd7ea555849a63 ben hengst committed Mar 5, 2013
Showing with 14 additions and 2 deletions.
  1. +3 −2 lib/perl5i/2/Meta/Instance.pm
  2. +11 −0 t/dump/formats.t
View
5 lib/perl5i/2/Meta/Instance.pm
@@ -138,7 +138,7 @@ sub is_equal {
return perl5i::2::equal::are_equal($$$self, $other);
}
-
+sub as_perl{shift->perl(@_)}
sub perl {
require Data::Dumper;
@@ -173,7 +173,7 @@ sub dump {
return $self->$dumper(%args);
}
-
+sub as_json { shift->_dump_as_json(@_)}
sub _dump_as_json {
require JSON;
my $json = JSON->new
@@ -198,6 +198,7 @@ sub _dump_as_json {
return $json->encode(${${$_[0]}});
}
+sub as_yaml { shift->_dump_as_yaml(@_)}
sub _dump_as_yaml {
require YAML::Any;
return YAML::Any::Dump(${${$_[0]}});
View
11 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.