Catalyst::Helper gutting complete

| No Comments | No TrackBacks
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:

sub get_sharedir_file {
    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";
}


After running make install, I don't have to do anything fancy to access these files when using File::ShareDir.  REALLY cool.

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!

No TrackBacks

TrackBack URL: http://www.codedright.net/mt/mt-tb.fcgi/33

Leave a comment

About this Entry

This page contains a single entry by Devin published on May 28, 2009 12:53 AM.

Ripping the Guts out of Catalyst::Helper was the previous entry in this blog.

SVN Rite of Passage is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Recent Photos

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.261