I've taken out all of the template files and hex data for images embedded in the __DATA__ section of Catalyst::Helper and put them into their own neat little share folder. Using File::ShareDir, I can just do something like this to get ahold of a file:
The only snag I've run into is images. I may very well have to take the hex data and stuff it into a template and render it thusly, as the images don't seem to be copying to the distribution's sharedir.
Much success tonight!
sub get_sharedir_file {After running make install, I don't have to do anything fancy to access these files when using File::ShareDir. REALLY cool.
my ($self, @filename) = @_;
my $file = file( dist_dir('Catalyst-Devel'), @filename);
warn $file;
my $contents = $file->slurp;
return $contents;
}
sub render_file {
my ( $self, $file, $path, $vars ) = @_;
$vars ||= {};
my $t = Template->new;
my $template = $self->get_sharedir_file( 'root', $file );
return 0 unless $template;
my $output;
$t->process( \$template, { %{$self}, %$vars }, \$output )
|| Catalyst::Exception->throw(
message => qq/Couldn't process "$file", / . $t->error() );
$self->mk_file( $path, $output );
}
sub _mk_test {
my $self = shift;
my $script = $self->{script};
my $appprefix = $self->{appprefix};
$self->render_file( 'test.tt', "$script/$appprefix\_test.pl" );
chmod 0700, "$script/$appprefix\_test.pl";
}
The only snag I've run into is images. I may very well have to take the hex data and stuff it into a template and render it thusly, as the images don't seem to be copying to the distribution's sharedir.
Much success tonight!







Leave a comment