Catalyst: June 2009 Archives

Everyone's got their preferred "stack" of modules + frameworks they like to use for any big project they use. I typically break mine down into a (web) framework, an ORM (or database interaction layer if you don't like ORMs), a templating system, caching, reverse proxy, application server (for instance, FastCGI for web stuff), web server software and version control.

Mine are:

  • Framework: Catalyst
  • ORM: DBIx::Class
  • Templating: Template::Toolkit -
  • Caching: memcached
  • Reverse proxy: Varnish (caching too)
  • Application server: FastCGI
  • Web server: nginx
  • Version control: git

Those may or may not be grouped together properly, but it's the best i could think of. Being a web developer, mine are all network/web oriented. Let's see yours! Add them to the Wiki Extras for this post, or just comment below!

File::ShareDir is a neat little module you can use to access your non-code files that you need to pack with your distribution. Files like images, Template::Toolkit templates, etc.

One cool use I've found for File::ShareDir is using it to replace the jumble of code that is currently being used for Catalyst::Helper's file generation. I was able to cut out the stuff from the DATA section, put it in a share/ directory in the distribution, run a make install and voila. I'm able to access my files, and even throw Path::Class into the mix to get easy file slurping and such.

Here's a bit of code I used:

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";
 }

file() is a Path::Class method for returning a file object, with which you can call ->slurp on and get its contents.

Easy!

Sponsored By


Ionzero: Rescue your dev project.

Following

Not following anyone

Note to spammers: all comments are moderated. Don't waste your time