Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #234 from notbenh/issue/230

Adding the as_* methods as requested in #230
  • Loading branch information...
commit 99d95e3885e11834774d4e3627ed433a7bcd7ce7 2 parents 93ae602 + 89e8a05
@schwern schwern authored
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';
Please sign in to comment.
Something went wrong with that request. Please try again.