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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |