Subject: | pitfalls/tricky parts to mention in the pod |
Playing with MooseX::Declare I've come across two points that
are not really bugs, but gotchas of the way M::D is implemented.
I think it may be a good idea to address those issues in the pod,
so that the caveat can emptor with all the information in his or
her possession.
1. lexical variables within a class { } or role { } don't work.
E.g., the following example will fail:
use MooseX::Declare;
class Foo {
my $i;
sub bar { ++$i; }
}
package main;
my $foo = Foo->new;
print $foo->bar;
I can't say I understand all the nitty gritty details of the
dark, dark black magic used by M::D and Devel::Declare, but
I think this is simply due to the exporting of the subs to
the class' namespace, which indeed means that the
final version of "bar" we'll be calling will not be in
the proper context to see '$i' anymore.
2. CPAN package version
This one is not a bug at all, but more of a general question of
how we should play nicely with CPAN, which of course doesn't
understand what 'class' means. The best way I've found so far
is to add a little header to the file:
{
package Language::l33t::Operators; # hi, CPAN, we're here!
our $VERSION = "0.03";
}
use MooseX::Declare;
role Language::l33t::Operators {
....
Assuming that I'm not off the mark with my description of the
problems and my fix for #2, I can come up with a pod patch if you
so desire.
PS: and, as always, thanks for creating M::D in the first place. Very
cool module. :-)