Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Moose and default values

by morgon (Curate)
on Feb 20, 2013 at 22:32 UTC ( #1019854=note: print w/replies, xml ) Need Help??

in reply to Re: Moose and default values
in thread Moose and default values

Nice, but why does it live in "PerlX" and not in "Moose" or "MooseX"?

Replies are listed 'Best First'.
Re^3: Moose and default values
by choroba (Chancellor) on Feb 20, 2013 at 22:34 UTC
    Probably you can use it outside Moose, too.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Indeed; it has no ties to Moose. It's simply a function that takes a list and returns a (possibly smaller) list. While it's handy to use it with Moose/Mouse/Moo constructors, it can be used with any functions that take a list of key-value pairs that you want to filter out undefs from.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
        It's nice (and only 10 lines of code :-=).

        But say I now wanted not only undefs but everything that is false (e.g. also an empty string) to trigger the default?

        Does Moose not have any mechanics for that?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2016-10-24 04:09 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.