Me too :)

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use IO::File; Main( @ARGV ); exit( 0 ); BEGIN { package Shack; use Moo; has( qw/ crabs is rw required 1 init_arg base /, builder => sub { warn "## BUILDER { @_ } @{[Data::Dump::pp( @_ )]}\n"; IO::File->new( $_[0] ) or die qq{"$_[0]": $!\n$^E\n }; }, ); $INC{'Shack.pm'} = __FILE__; } sub Main { use Shack; dd( Shack->new( base => __FILE__ ) ); dd( Shack->new( crabs => __FILE__ ) ); } __END__ bless({ crabs => "crabshack.pl" }, "Shack") ## BUILDER { Shack=HASH(0xc3f7ec) } bless({}, "Shack") "Shack=HASH(0xc3f7ec)": No such file or directory The system cannot find the file specified at crabshack.pl line 23.

So BUILDER doesn't get called if there is a base argument (named in init_arg

I think the idea is to have

has qw/ base required 1 /; has qw/ crabs is rw / , builder => sub { IO::File->new( $self->base ) +or ... };

But I don't get it, even after looking at
https://metacpan.org/source/HAARG/Moo-1.003000/t/init-arg.t
https://metacpan.org/source/HAARG/Moo-1.003000/t/lazy_isa.t

No, I'm not familiar with Moose way of doing OOP, maybe the Moose docs explain the concepts better so the Moo docs make sense, but I'm not that interested


In reply to Re: Confusion with Moo's builder attribute and a file handle (code) by Anonymous Monk
in thread Confusion with Moo's builder attribute and a file handle by mgatto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.