From: Vincent Pit Date: Tue, 6 Aug 2013 18:34:25 +0000 (-0300) Subject: Fix the autocoercing code with recent versions of Moose X-Git-Tag: rt87282~1 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=commitdiff_plain;h=3984d6843fc2b502ea57bc9688932435fba14663 Fix the autocoercing code with recent versions of Moose With Moose, it is no longer possible to have a coercing attribute in an immutable class be updated with coercions loaded "late". These semantics are actually quite understandable, but on the other hand there's no easy way to recover which attributes coerce to a given type coercion, which would allow us to manually force the recompilation of the coercing code for the attributes. Thus we have to make the classes that contain such an attribute mutable when Moose is in use. --- diff --git a/lib/LaTeX/TikZ/Formatter.pm b/lib/LaTeX/TikZ/Formatter.pm index afdbd38..e5bb3cf 100644 --- a/lib/LaTeX/TikZ/Formatter.pm +++ b/lib/LaTeX/TikZ/Formatter.pm @@ -361,7 +361,7 @@ LaTeX::TikZ::Interface->register( }, ); -__PACKAGE__->meta->make_immutable; +__PACKAGE__->meta->make_immutable if any_moose() ne 'Moose'; =head1 SEE ALSO diff --git a/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm b/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm index 0356cb0..7671ade 100644 --- a/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm +++ b/lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm @@ -47,7 +47,9 @@ our $VERSION = '0.02'; coerce => 1, handles => [ 'id' ], ); - __PACKAGE__->meta->make_immutable; + # This class shouldn't be immutable when using Moose, or the + # coercing attributes will not be updated with the future coercions. + __PACKAGE__->meta->make_immutable if any_moose() ne 'Moose'; } # Another class the user wants to use instead of X (cannot be changed) diff --git a/lib/LaTeX/TikZ/Set/Point.pm b/lib/LaTeX/TikZ/Set/Point.pm index 4cf7992..6e78e66 100644 --- a/lib/LaTeX/TikZ/Set/Point.pm +++ b/lib/LaTeX/TikZ/Set/Point.pm @@ -154,7 +154,7 @@ LaTeX::TikZ::Functor->default_rule( } ); -__PACKAGE__->meta->make_immutable; +__PACKAGE__->meta->make_immutable if any_moose() ne 'Moose'; =head1 SEE ALSO diff --git a/t/02-autocoerce.t b/t/02-autocoerce.t index 86d49cc..cbfb6e3 100644 --- a/t/02-autocoerce.t +++ b/t/02-autocoerce.t @@ -108,7 +108,7 @@ use LaTeX::TikZ::Meta::TypeConstraint::Autocoerce; coerce => 1, ); - __PACKAGE__->meta->make_immutable; + __PACKAGE__->meta->make_immutable if any_moose() ne 'Moose'; sub main::Z () { __PACKAGE__ } }