Nope,
Not specifying 'is' is a valid use case ...
has foo => ( reader => 'set_foo', ... );
and not having any accessors at all is also a valid use case since you
can set it via the constructor and have side-effectual triggers and
such ..
has foo => ( trigger => sub { my ($self, $value) = @_; $self-
>bar( $value + 2 ) } );
has bar => ( is => 'rw', ... );
And of course you are welcome to violate encapsulation too, it is bad
form, but we won't stop you.
Raising a warning here would be a bad idea because we cannot detect
the validity or not.
The best solution to this is to add onto the Perl::Critic::Moose
policies (http://search.cpan.org/~elliotjs/Perl-Critic-Moose-0.999_002/lib/Perl/Critic/Moose.pm
) and then it is entirely optional, customizable and override-able.
- Stevan
On Jun 3, 2009, at 1:06 PM, Mark Morgan wrote:
This behaviour has bitten me a few times too, taking quite a bit of
time to find the cause of. Is there any intention to give a default
'is' value, or raise a warning, if no access parameters are given?
Mark.
On Wed, Jun 3, 2009 at 3:09 PM, mikhail maluyk <mikhail.mal...@gmail.com
> wrote:
Hi,
"has" doesn't create an accessor for an attribute. "is" or
"accessor" does.
On Wed, Jun 3, 2009 at 8:00 PM, Ovid <publiustemp-
catal...@yahoo.com> wrote:
Could someone please explain to me what I'm doing wrong here?
#!/usr/bin/env perl
{
package My::Base;
use Moose;
has some_method => ( default => 'foo' );
}
{
package My::Class;
use Moose;
extends 'My::Base';
}
print My::Base->new->some_method;
__END__
Can't locate object method "some_method" via package "My::Base"
at
inherit.pl line 16.
Changing the some_method attribute to the following makes this go
away:
has some_method => ( is => 'rw', default => 'foo' );
(is => 'ro', default => 'foo') also works.
Is this a bug or have I misunderstood something? This is Moose
0.79 and
perl, v5.8.8 built for i486-linux-gnu-thread-multi. (Also fails on
Solaris,
so I doubt it's an OS issue).
If this is a bug, I'll file a report.
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
--
Regards,
Mikhail