msgpack/perl/lib/Data/MessagePack.pm

86 lines
1.6 KiB
Perl
Raw Normal View History

2009-04-15 12:55:41 +09:00
package Data::MessagePack;
use strict;
use warnings;
2009-07-01 17:45:18 +09:00
use 5.008001;
2009-04-15 12:55:41 +09:00
2010-09-01 08:19:05 +09:00
our $VERSION = '0.15';
our $PreferInteger = 0;
2009-04-15 12:55:41 +09:00
2009-07-30 16:22:00 +09:00
our $true = do { bless \(my $dummy = 1), "Data::MessagePack::Boolean" };
our $false = do { bless \(my $dummy = 0), "Data::MessagePack::Boolean" };
sub true () { $true }
sub false () { $false }
if ( !__PACKAGE__->can('pack') ) { # this idea comes from Text::Xslate
2010-09-01 16:04:25 +09:00
my $backend = $ENV{ PERL_DATA_MESSAGEPACK } || '';
if ( $backend !~ /\b pp \b/xms ) {
eval {
require XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);
};
2010-09-01 16:04:25 +09:00
die $@ if $@ && $backend =~ /\b xs \b/xms; # force XS
}
if ( !__PACKAGE__->can('pack') ) {
require 'Data/MessagePack/PP.pm';
}
}
2009-04-15 12:55:41 +09:00
1;
__END__
=head1 NAME
Data::MessagePack - messagepack
=head1 SYNOPSIS
my $packed = Data::MessagePack->pack($dat);
my $unpacked = Data::MessagePack->unpack($dat);
=head1 DESCRIPTION
Data::MessagePack is a binary packer for perl.
2010-05-03 01:09:21 +09:00
=head1 METHODS
=over 4
=item my $packed = Data::MessagePack->pack($data);
pack the $data to messagepack format string.
=item my $unpacked = Data::MessagePack->unpack($msgpackstr);
unpack the $msgpackstr to messagepack format string.
=back
=head1 Configuration Variables
=over 4
=item $Data::MessagePack::PreferInteger
Pack the string as int when the value looks like int(EXPERIMENTAL).
=back
2009-04-15 12:55:41 +09:00
=head1 AUTHORS
Tokuhiro Matsuno
=head1 THANKS TO
Jun Kuriyama
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
2009-04-15 12:55:41 +09:00
=head1 SEE ALSO
L<http://msgpack.sourceforge.jp/>