develooper Front page | perl.moose | Postings from November 2015

Re: $meta->superclasses()

Thread Previous
From:
Bill Moseley
Date:
November 22, 2015 18:43
Subject:
Re: $meta->superclasses()
Message ID:
CAKhN_m5DO9TqSpMRZPO_+ky6zjQo4xJPa8Wjy0d91jn3FhVRUw@mail.gmail.com
On Sat, Nov 21, 2015 at 8:01 PM, Chris Prather <perigrin@prather.org> wrote:

> You are setting the superclasses explicitly so you're not inheriting from
> Moose::Object which defines the hooks that call BUILDARGS.
>

Maybe I'm not following.  The Catalyst code does this:


>
>>             my $meta = Class::MOP::get_metaclass_by_name($class);
>>             $meta->superclasses($plugin, $meta->superclasses);
>>
>
In this case $plugin = 'Catalyst::Plugin::MyPlugin', and
$meta->superclasses = 'Catalyst'.  Again, Catalyst extends
Catalyst::Component, where BUILDARGS is defined.

I'm not clear how MI is suppose to work, but what I'm seeing is BUILDARGS
is now called in $plugin, and not in Catalyst::Component.

By reversing the order like this:

$meta->superclasses($meta->superclasses, $plugin);


the BUILDARGS is called in Catalyst::Component and not in the $plugin.

This is only an issue when the plugin uses Moose, but that's pretty
common.  Plugins written as roles are fine, of course.


Oh, BTW -- the init_arg problem seems to be related
to MooseX::Emulate::Class::Accessor::Fast.

This code:

package Foo;
use Moose;
use Data::Dumper;
with 'MooseX::Emulate::Class::Accessor::Fast';

has foo => (
    is  => 'ro',
    isa => 'Int', # for error
    init_arg => undef,
);


package main;
use strict;
use warnings;

my $foo = Foo->new( { foo => 'bar' } );

use Data::Dumper;
print Dumper $foo->foo;


Generates this:

$VAR1 = 'bar';


 Which should not have been set -- and clearly isn't an Int.

-- 
Bill Moseley
moseley@hank.org

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About