Skip to content

Commit

Permalink
perl: add JSON.pm-like interface: Data::MessagePack->new->encode(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuji Goro committed Aug 19, 2011
1 parent 92718e2 commit 356b7b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions perl/lib/Data/MessagePack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ if ( !__PACKAGE__->can('pack') ) { # this idea comes from Text::Xslate
}
}

sub new {
my($class) = @_;
return bless {}, $class;
}

sub encode; *encode = __PACKAGE__->can('pack');
sub decode; *decode = __PACKAGE__->can('unpack');

1;
__END__
Expand Down
15 changes: 15 additions & 0 deletions perl/t/18_new_interface.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!perl
use strict;
use warnings;

use Test::More;

use Data::MessagePack;

my $mp = Data::MessagePack->new();

is_deeply $mp->decode( $mp->encode(\%ENV) ), \%ENV;


done_testing;

0 comments on commit 356b7b4

Please sign in to comment.