Hi

I'm trying to let people use shortcuts instead of specifying full paths.

Want to do this by replacing all instances of __SOURCE__ in properties of 
type ExistingFile with the contents of property source_dir 

Replacing ALL instances of __SOURCE__ in all property types is OK too I 
guess 

Had some ideas, but both seem to have problems 
* Within Constructor - but how can I find all properties of type 
ExistingFile?
* Within ExistingFile subtype - but how do I get to the parent's 
source_dir parameter? Seems only value passed into where {}
* Trigger - seems that triggers get called After the validation, so the 
ExistingFile validation fails
Any ideas? 



Here's my source

make_test.pl 

use strict; 
use warnings; 

use TestStuff; 

my $test = TestStuff->new( 
    { 
        source_dir => '/home/bhumph/', 
        some_file => '__SOURCE__foo.txt' 
    } 
); 




TestStuff.pm 

package TestStuff; 

use Moose; 
use Moose::Util::TypeConstraints; 

use Data::Dumper; 

subtype ExistingFile 
        => as 'Str' 
        => where { print Dumper($_); -f $_ } 
        => message { 'Must be an existing file' }; 

sub BUILD { 
    my ($self, @stuff) = @_; 

    print Dumper(\...@_); 
} 

has source_dir => ( 
        isa => 'Str', 
        is  => 'ro', 
        required => 1 
); 

has some_file => ( 
        isa => 'ExistingFile', 
        is  => 'ro' 
); 

1; 

Reply via email to