I typically see classes with delegated methods use a

default => sub { {} }, 

or 

default => sub { [] },

stanza in the definition(s) depending on whether they're Hash or Array traits.

I agree this should be better documented though

Mark


________________________________
 From: Faelin McCaley Landy <faelin.la...@gmail.com>
To: Chris Weyl <cw...@alumni.drew.edu>; Moose Mailing List <moose@perl.org> 
Sent: Tuesday, June 25, 2013 4:54 PM
Subject: Re: Issue with HashRef attritubes
 


Here's a sample of the code in question (assume the appropriate pragmas for 
type constraints):


>
>has 'locations' => (
>    traits  => ['Hash'],
>    is  => 'ro',
>    isa => 'HashRef[Location]',
>    handles => {
>        add_loc=> 'set',
>        del_loc=> 'delete',
>        get_loc=> 'get',
>loc_keys=> 'keys',
>loc_vals=> 'values',
>        no_locs=> 'is_empty',
>        loc_count=> 'count',
>loc_pairs=> 'kv',
>    },
>);
>
>
>
>
>has 'regions' => (
>    traits  => ['Hash'],
>    is  => 'ro',
>    isa => 'HashRef[Region]',
>    handles => {
>        add_region=> 'set',
>        del_region=> 'delete',
>        get_region=> 'get',
>region_keys=> 'keys',
>region_vals=> 'values',
>        no_regions=> 'is_empty',
>        region_count=> 'count',
>region_pairs=> 'kv',
>    },
>);
>
>When I attempt to access the locations hashref or its handles from within this 
>class, I only get an error saying that it could not find the requested 
>hash/function. However, when I attempt to access the regions hashref/handles, 
>it has no problems.

Side note, I'm using namespace::sweep if that makes a difference.




On Mon, Jun 24, 2013 at 11:46 PM, Chris Weyl <cw...@alumni.drew.edu> wrote:

On Mon, 24 Jun 2013, Faelin McCaley Landy wrote:
>
>
>Moose, you do confound me so! Any ideas, guys?
>>
>Not without seeing some of the code in question :)
>
>                      -Chris
>
>

Reply via email to