Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo

by Your Mother (Archbishop)
on May 01, 2019 at 18:35 UTC ( [id://1233239]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo
in thread Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo

Terrific. By manually I meant this more than isa/blessed

my $type = InstanceOf['FishTaco::Topping']; … if ( $type->($topping) ) …
  • Comment on Re^4: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: Trouble with, or misunderstanding of, Types::Standard ArrayRef[elements] enforcement in Moo
by tobyink (Canon) on May 03, 2019 at 13:23 UTC

    $type->($value) is a live-or-die function rather than returning a boolean. It returns $value if it lives. Makes it easy to do something like:

    sub set_name { my $self = Object->( shift ); my $value = Str->( shift ); $self->{name} = $value; } sub get_name { my $self = Object->( shift ); return $self->{name}; }

    $type->check($value) returns a boolean.

    Exporting an is_Topping (boolean) or assert_Topping (live or die) function will be faster because it will avoid overhead from things like overloading, method lookups, etc. Though what you've already got is unlikely to be a major bottleneck for your application, so I'd mostly say go with what you feel is more readable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1233239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found