Hi Stevan,

this is not really a bug report, it's more a demand of a feature to be
included in the long run, because it might force heavy changes inside
the handling of type constraint error messages. And it's not essential
for using Moose.

If defining subtypes as

# / (root) forbidden
# no umlauts, no special chars
#
subtype 'FilePathString'
 => as 'Str'
 => where   { $_ =~ m#^(/[a-zA-Z0-9_.-]+)+$#; }
 => message { "FilePath invalid ($_)" };

subtype 'FilePath'
 => as 'FilePathString'
 => where   { -e $_; }
 => message { "FilePath must exist ($_)" };

and using them as

package Foo;
has 'path' =>
(
 is       => 'ro',
 isa      => 'FilePath',
 required => 1,
);

I get as error message always 'FilePath must exist' instead of the
expected 'FilePath invalid', when I call

Foo->new ( path => '/' );

Do I miss something?

Please have a look at
http://dienstleistung-kultur.de/moose/05_type_message.t.txt

As said, I can live without special messages, but I love, when things
are complete ;-)

        Ernesto


P.S.: Re-reading this mail it comes to my mind, that I'm not shure about
the order of the type constraint processing.

Maybe I'm better off with something like

subtype 'FilePath'
 => as 'Str'
 => where
    {
        return undef      unless $_ =~ m#^(/[a-zA-Z0-9_.-]+)+$#;
        return undef      unless -e $_;
        return 1;
    };
    (using the default messages)

to be shure, that the wellformness of the path is checked before its
existence to avoid handing over malicious paths to the OS.
Comments?


P.P.S.: My environment:
Perl v5.8.8 on Debian 4.0 Etch
Moose 0.40 with Moose::Object 0.12 (!)
Class::MOP 0.54



Reply via email to