pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks!
Is it possible to use the type constraint stuff in Moose to de-taint values?
For instance, I have a class with a few file paths. Pre-Moose I would have checked them individually with a regex to de-taint them. Now I have this cool Moose type checking system, but I don't see how to de-taint values with it.
For instance:
# old way sub logfile { my $self = shift; my $new_name = shift; if ( !defined($new_name) ) { return $self->{logfile}; } if ( $new_name !~ m{^([\w/_\-\.]{1,80})$} ) { croak "I don't trust logfile name '$new_name'"; } $self->{logfile} = $1; } # New Moose Way subtype 'FilePath' => as 'Str' => where { $_ =~ m{^([\w/_\-\.]{1,80})$} } => message { "I don't trust file name '$_'" }; has logfile => ( is => 'rw', isa => 'FilePath', default => '/var/log/walrus.log' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose types & taint removal?
by ikegami (Patriarch) on Aug 11, 2010 at 19:23 UTC | |
by pileofrogs (Priest) on Aug 12, 2010 at 16:28 UTC | |
by pileofrogs (Priest) on Aug 12, 2010 at 21:02 UTC | |
|
Re: Moose types & taint removal?
by stvn (Monsignor) on Aug 11, 2010 at 18:24 UTC |