1398 links
  • linx
  • Home
  • Login
  • RSS Feed
  • ATOM Feed
  • Tag cloud
  • Picture wall
  • Daily
  • ► Play Videos
Links per page: 20 50 100
page 1 / 1
3 results tagged moose x
  • Moose and enum
    February 14, 2022 at 9:47:59 AM UTC - permalink -
    QRCode
    - https://damien.krotkine.com/2011/06/17/enum-in-moose.html
    enum moose object oop perl
  • thumbnail
    How can I prevent Perl Moose Read-Only Attributes being set upon a call to new? - Stack Overflow

    Use the init_arg attribute configuration (see "Constructor parameters" in Moose::Manual::Attributes):

    package SOD::KuuAnalyze::ProdId;
    use Moose;
    
    has 'users' => (
        isa => 'ArrayRef[Str]', is => "ro",
        init_arg => undef,    # do not allow in constructor
    );
    1;
    February 3, 2022 at 9:58:55 AM UTC - permalink -
    QRCode
    - https://stackoverflow.com/questions/1814046/how-can-i-prevent-perl-moose-read-only-attributes-being-set-upon-a-call-to-new
    attributes moose new-operator perl privacy
  • thumbnail
    Moose attribute initialization

    BUILD is called after the constructor, which makes it handy to verify state but not necessarily useful to format incoming arguments.

    BUILDARGS would let you modify incoming arguments before the constructor is called, which makes it a better fit for this case. Your attribute is read-only, so this could work.

    But... if you're hungry for static typing, why would you stop after promising "this is a string"? If you create a subtype for ISO8601 strings, you can promise "this is a string and it has X format". Even better, you're doing that in a way that's immediately and trivially portable to other attributes.

    I rather doubt the regex below will work for you, but I hope it will get the point across:

    #define the type
    subtype 'iso8601',
        as 'Str',
        where { /\d{4}-\d{2}-\d{2}/ },
        message { "Not a valid ISO8601 string ($_)" };
    
    #provide a coercion
    coerce 'iso8601',
        from 'Str',
        via { _format_as_iso8601 $_ };
    
    #tell moose to coerce the value
    has startdate  => (is => 'ro', isa => 'iso8601', required => 1, coerce => 1);
    November 15, 2019 at 3:36:27 PM UTC - permalink -
    QRCode
    - https://stackoverflow.com/questions/22104385/moose-attribute-initialization
    attribute initialisation moose perl validation
Links per page: 20 50 100
page 1 / 1
Shaarli - The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community - Help/documentation