Finding your Share Directory in your Distribution

| No Comments | No TrackBacks
So, previously I spoke about having to make install after every code change to have tests run properly under prove -l  t/test_name.t.  This is obviously quite a bitch.

So after some question asking in #catalyst-dev, mst kindly pointed me to some code he'd written for Reaction to do just this very thing:

sub _find_share_dir {
  my ($self, $args) = @_;
  my $share_name = $self->name;
  if ($share_name =~ s!^/(.*?)/!!) {
    my $dist = $1;
    $args->{share_base_dir} = eval {
        Dir->new(File::ShareDir::dist_dir($dist))
           ->subdir('share');
    };
    if ($@) {
        # not installed
        my $file = __FILE__;
        my $dir = Dir->new(dirname($file));
        my $share_base;
        while ($dir->parent) {
            if (-d $dir->subdir('share') && -d $dir->subdir('share')->subdir('root')) {
                $share_base = $dir->subdir('share')->subdir('root');
                last;
            }
            $dir = $dir->parent;
        }
        confess "could not find sharebase by recursion. ended up at $dir, from $file"
          unless $share_base;
        $args->{share_base_dir} = $share_base;
    }
  }
  my $base = $args->{share_base_dir}->subdir($share_name);
  confess "No such share base directory ${base}"
    unless -d $base;
  $self->share_dir($base);
};


This is neat, and will really help me to make changes and test them faster, instead of having to remember to do make install each time and banging my head on the desk until I realize i didn't run it, thus, the errors that seem to never disappear.

No TrackBacks

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

Leave a comment

About this Entry

This page contains a single entry by Devin published on May 30, 2009 5:11 PM.

SVN Rite of Passage was the previous entry in this blog.

RFC: Catalyst::Helper API 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