--- Types-Serialiser/Serialiser.pm 2013/10/27 22:46:21 1.3 +++ Types-Serialiser/Serialiser.pm 2013/10/28 15:28:44 1.4 @@ -17,7 +17,9 @@ package Types::Serialiser; -our $VERSION = 0.01; +use common::sense; # required to suppress annoying warnings + +our $VERSION = 0.02; =head1 SIMPLE SCALAR CONSTANTS @@ -97,6 +99,13 @@ =cut +BEGIN { + # for historical reasons, and to avoid extra dependencies in JSON::PP, + # we alias *Types::Serialiser::Boolean with JSON::PP::Boolean. + package JSON::PP::Boolean; + *Types::Serialiser::Boolean:: = *JSON::PP::Boolean::; +} + our $true = do { bless \(my $dummy = 1), Types::Serialiser::Boolean:: }; our $false = do { bless \(my $dummy = 0), Types::Serialiser::Boolean:: }; our $error = do { bless \(my $dummy ), Types::Serialiser::Error:: }; @@ -110,7 +119,7 @@ sub is_false ($) { !$_[0] && UNIVERSAL::isa $_[0], Types::Serialiser::Boolean:: } sub is_error ($) { UNIVERSAL::isa $_[0], Types::Serialiser::Error:: } -package Types::Serialiser::Boolean; +package Types::Serialiser::BooleanBase; use overload "0+" => sub { ${$_[0]} }, @@ -118,6 +127,8 @@ "--" => sub { $_[0] = ${$_[0]} - 1 }, fallback => 1; +@Types::Serialiser::Boolean::ISA = Types::Serialiser::BooleanBase::; + package Types::Serialiser::Error; sub error { @@ -141,6 +152,12 @@ While it is possible to use an isa test, directly comparing stash pointers is faster and guaranteed to work. +For historical reasons, the C stash is +just an alias for C. When printed, the classname +withh usually be C, but isa tests and stash pointer +comparison will normally work correctly (i.e. Types::Serialiser::true ISA +JSON::PP::Boolean, but also ISA Types::Serialiser::Boolean). + =head1 A GENERIC OBJECT SERIALIATION PROTOCOL This section explains the object serialisation protocol used by