Moose/mouse r/o variables

[email protected] (Peter Gordon)
Newsgroups perl.moose
Message-ID <1301315296.1891.88.camel@qed>
I have a small class, where I would like the variables to be read only
by external calls, but rw for internal access.

Why? 
If there is a variable defined as lazy and ro, writing the value fails.
So it needs to be rw. Is there a recommended way of dealing with this
problem?

The other reason I have is that the class in question is instantiated
with a filename, and the filename must exist. If the file gets deleted
before the default for value is performed, I would like to get an error.
The easiest way that I found for that was to read and write the filename
value, forcing the isa FileExists. Is there a better way of doing this? 


subtype 'FileExists'
    => as 'Str'
    => where { -e $_ };

has 'fileName' => (is => 'rw',
		   required => 1,
                   isa => 'FileExists',
		  ) ;

has 'value'   => (is => 'rw',
	       lazy => 1,
	       builder => 'value_builder',
	      ) ;

sub value_builder { 
    my $my = shift ;

    $my->fileName($my->fileName) ; # This forces the isa requirement
    $my->value('123') ;	
} 

Peter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.