[Perl5-syntax] Method::Signatures, now with types
Buddy Burden
barefootcoder at gmail.com
Tue Mar 22 03:25:10 GMT 2011
Nick,
>> I'll see about possibly adding in the ability to choose at import in
>> MXD the ability to use this over MXMS. Shouldn't take too much since
>> the underlying mechanism is the same.
>
> This is actually what I was just about to start on myself. I was
> thinking about it in terms of subclassing (based on your earlier
> message to me on this list), but if it could be an option within MXD,
> I think that would be even better.
Okay, I started. :) But I can't quite figure out how to do this.
I'm going by your message to me here on 2/23, where you said:
> MooseX::Declare::Keyword::Method->meta
> ->add_around_method_modifier(
> 'parse',
> sub {
> # Your code here
> });
>
> So I would write a module that rigged up MS how you would like it and
> then have an import method that would access the metaclasses of stuff
> inside MXD and make whatever changes you want.
>
> That way you could have this:
>
> use MooseX::Declare;
> use Replace::MXMS::With::MS;
>
> class Foo { ... }
>
> The MOP is there explicitly for reasons like this, so you can alter the
> internals of things without resorting to ugly stash access.
But the problem I seem to be having is that MXMS _hasa_
Context::Simple, whereas MS _isa_ Context::Simple. So I can't figure
out what to do with the context argument to parse(). In a fit of
pique, I tried reblessing the context arg into MS, but that didn't
work (no surprise there <g>). No matter what I try, I always get an
error like so:
Use of uninitialized value in subroutine entry at
/usr/local/lib64/perl5/Devel/Declare/Context/Simple.pm line 38.
Use of uninitialized value $decl in concatenation (.) or string at
/usr/local/lib64/perl5/Devel/Declare/Context/Simple.pm line 39.
Couldn't find declarator '' at
/usr/local/lib64/perl5/Devel/Declare/Context/Simple.pm line 39
Devel::Declare::Context::Simple::skip_declarator('Method::Signatures=HASH(0x2dafd98)')
called at /usr/local/lib64/perl5/Devel/Declare/MethodInstaller/Simple.pm
line 56
Devel::Declare::MethodInstaller::Simple::parser('Method::Signatures=HASH(0x2dafd98)')
called at MXD_MS.pm line 19
Class::MOP::Class:::around('CODE(0x28bdb00)',
'MooseX::Declare::Syntax::Keyword::Method=HASH(0x2da9210)',
'Method::Signatures=HASH(0x2dafd98)') called at
/usr/local/lib64/perl5/Class/MOP/Method/Wrapped.pm line 159
Class::MOP::Method::Wrapped::__ANON__('MooseX::Declare::Syntax::Keyword::Method=HASH(0x2da9210)',
'Method::Signatures=HASH(0x2dafd98)') called at
/usr/local/lib64/perl5/Class/MOP/Method/Wrapped.pm line 89
MooseX::Declare::Syntax::Keyword::Method::parse('MooseX::Declare::Syntax::Keyword::Method=HASH(0x2da9210)',
'Method::Signatures=HASH(0x2dafd98)') called at
/usr/local/share/perl5/MooseX/Declare/Syntax/KeywordHandling.pm line
97
MooseX::Declare::Syntax::KeywordHandling::parse_declaration('MooseX::Declare::Syntax::Keyword::Method=HASH(0x2da9210)',
'NewModelMoose.pm', 'HASH(0x2da9138)', 'method', 1) called at
/usr/local/share/perl5/MooseX/Declare/Syntax/KeywordHandling.pm line
51
MooseX::Declare::Syntax::KeywordHandling::__ANON__('method',
1) called at /usr/local/lib64/perl5/Devel/Declare.pm line 274
Devel::Declare::linestr_callback('const', 'method', 1) called
at NewModelMoose.pm line 7
require NewModelMoose.pm called at ./errs line 12
main::BEGIN() called at NewModelMoose.pm line 7
eval {...} called at NewModelMoose.pm line 7
Compilation failed in require at ./errs line 12.
BEGIN failed--compilation aborted at ./errs line 12.
My current code (with the probably ill-advised rebless) looks like this:
package MXD_MS;
use Class::MOP;
sub import
{
Class::MOP::load_class('MooseX::Declare');
Class::MOP::load_class('Method::Signatures');
my $meta = MooseX::Declare::Syntax::Keyword::Method->meta;
$meta->make_mutable();
$meta->add_around_method_modifier
(
parse => sub
{
my ($orig, $self, $ctx) = @_;
my $ms = bless $ctx, 'Method::Signatures';
$ms->parser;
}
);
$meta->make_immutable();
}
1;
I also tried ignoring $ctx altogether (which was probably equally
ill-advised), and just calling Method::Signatures->new, but that gives
the exact same error. Any thoughts? (Or let me know if you think I
should repost on Moose or somesuch.)
-- Buddy
More information about the Perl5-syntax
mailing list