Skip Menu |

This queue is for tickets about the JSON-MaybeXS CPAN distribution.

Report information
The Basics
Id: 102733
Status: resolved
Priority: 0/
Queue: JSON-MaybeXS

People
Owner: Nobody in particular
Requestors: genehack [...] genehack.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.003004



Subject: Documentation should indicate ->new() is factory, not constructor
Date: Thu, 12 Mar 2015 12:14:44 -0700
To: bug-JSON-MaybeXS [...] rt.cpan.org
From: John SJ Anderson <genehack [...] genehack.org>
See https://github.com/fayland/perl-net-github/issues/61 for context. Should take Ether's advice on that ticket and add it to the docs. Also: <mst> yeah, and perhaps explicitly mentioning that ->isa(JSON::MaybeXS::JSON) would work
Patch attached.
Subject: 0001-Add-CAVEAT-section-about-type-checking-RT-102733.patch
From d4dd11da82e39761d11ccd215e5d99467b8da558 Mon Sep 17 00:00:00 2001 From: John SJ Anderson <genehack@genehack.org> Date: Fri, 13 Mar 2015 15:53:07 -0700 Subject: [PATCH] Add CAVEAT section about type checking [RT#102733] --- lib/JSON/MaybeXS.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/JSON/MaybeXS.pm b/lib/JSON/MaybeXS.pm index 2f90001..cd20183 100644 --- a/lib/JSON/MaybeXS.pm +++ b/lib/JSON/MaybeXS.pm @@ -223,6 +223,27 @@ To include JSON-aware booleans (C<true>, C<false>) in your data, just do: my $true = JSON->true; my $false = JSON->false; +=head1 CAVEATS + +The C<new()> method in this module is technically a factory, not a +constructor, because the objects it returns will I<NOT> be blessed into the +C<JSON::MaybeXS> class. + +If you are using an object returned by this module as a Moo(se) attribute, +this type constraint code: + + is 'json' => ( isa => 'JSON::MaybeXS' ); + +will I<NOT> do what you expect. Instead, either rely on the C<JSON> class +constant described above, as so: + + is 'json' => ( isa => JSON::MaybeXS::JSON() ); + +Alternatively, you can use duck typing: + + use Moose::Util::TypeConstraints; + is 'json' => ( isa => Object , duck_type([qw/ encode decode /])); + =head1 AUTHOR mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk> -- 2.3.0
Patch attached.
Subject: 0001-Add-CAVEAT-section-about-type-checking-RT-102733.patch
From d4dd11da82e39761d11ccd215e5d99467b8da558 Mon Sep 17 00:00:00 2001 From: John SJ Anderson <genehack@genehack.org> Date: Fri, 13 Mar 2015 15:53:07 -0700 Subject: [PATCH] Add CAVEAT section about type checking [RT#102733] --- lib/JSON/MaybeXS.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/JSON/MaybeXS.pm b/lib/JSON/MaybeXS.pm index 2f90001..cd20183 100644 --- a/lib/JSON/MaybeXS.pm +++ b/lib/JSON/MaybeXS.pm @@ -223,6 +223,27 @@ To include JSON-aware booleans (C<true>, C<false>) in your data, just do: my $true = JSON->true; my $false = JSON->false; +=head1 CAVEATS + +The C<new()> method in this module is technically a factory, not a +constructor, because the objects it returns will I<NOT> be blessed into the +C<JSON::MaybeXS> class. + +If you are using an object returned by this module as a Moo(se) attribute, +this type constraint code: + + is 'json' => ( isa => 'JSON::MaybeXS' ); + +will I<NOT> do what you expect. Instead, either rely on the C<JSON> class +constant described above, as so: + + is 'json' => ( isa => JSON::MaybeXS::JSON() ); + +Alternatively, you can use duck typing: + + use Moose::Util::TypeConstraints; + is 'json' => ( isa => Object , duck_type([qw/ encode decode /])); + =head1 AUTHOR mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk> -- 2.3.0
On 2015-03-13 16:01:52, GENEHACK wrote: Show quoted text
> Patch attached.
Thanks, released in 1.003004!