Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

union isn't finding the types

0 views
Skip to first unread message

Caleb Cushing

unread,
Feb 18, 2013, 6:22:34 PM2/18/13
to mo...@perl.org
the code,

use Class::Load 0.20 'load_class';
use Moose::Role;

# VERSION

#### Attribute Definitions ####

has _log => (
isa => 'Log::Any::Adapter::Base | Log::Any::Adapter::Null',
is => 'ro',
lazy => 1,
default => sub { load_class('Log::Any')->get_logger },
);


attached is the the stack trace, what about unions do I not
understand? are they only allowed between moose native types? or am I
doing something else that is obviously wrong?


--
Caleb Cushing

http://xenoterracide.com
stack.txt

Ben Tilly

unread,
Feb 18, 2013, 11:35:16 PM2/18/13
to Caleb Cushing, mo...@perl.org
This is documented, sort of.

http://search.cpan.org/dist/Moose/lib/Moose/Manual/Types.pod#WHAT_IS_A_TYPE?

Any Moose type is automatically a type. Any created type is a type.
Any reference to something unknown is assumed to be a type. But the
magic breaks down when you've got complex expressions, pieces of which
are non-Moose classes.

So add in:

subtype 'Log::Any::Adaptor::Base', as 'Object', where
{$_->isa('Log::Any::Adaptor::Base')};
subtype 'Log::Any::Adapter::Null', as 'Object', where
{$_->isa('Log::Any::Adapter::Null')};

and it should work.

Jesse Luehrs

unread,
Feb 18, 2013, 11:47:01 PM2/18/13
to Ben Tilly, Caleb Cushing, mo...@perl.org
On Mon, Feb 18, 2013 at 08:35:16PM -0800, Ben Tilly wrote:
> This is documented, sort of.
>
> http://search.cpan.org/dist/Moose/lib/Moose/Manual/Types.pod#WHAT_IS_A_TYPE?
>
> Any Moose type is automatically a type. Any created type is a type.
> Any reference to something unknown is assumed to be a type. But the
> magic breaks down when you've got complex expressions, pieces of which
> are non-Moose classes.
>
> So add in:
>
> subtype 'Log::Any::Adaptor::Base', as 'Object', where
> {$_->isa('Log::Any::Adaptor::Base')};
> subtype 'Log::Any::Adapter::Null', as 'Object', where
> {$_->isa('Log::Any::Adapter::Null')};
>
> and it should work.

A shorter way to write that is "class_type('Log::Any::Adaptor::Base')".

-doy
0 new messages