May 2009 Archives

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.

SVN Rite of Passage

| No Comments | No TrackBacks
Git makes it so easy.  I can't wait until the Catalyst repo is converted completely to Git.

At least i can do stuff like svn add *.tt, instead of having to manually specify each individual file.  Keeps me from having to learn how to use svn:ignore too!

Also, I'd really like to figure out how to get File::ShareDir *not* look into the installed distro's share directory when doing testing on a local branch.  I have to make install every time I make any sort of change.  This of course sucks.

More later.
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!
I've started my first few steps into ripping the guts out of Catalyst::Helper.  The "guts" being the Template::Toolkit templating in the __DATA__ section and the *awful and hideous* hex representation of the Catalyst logo images stuff in there as well.

The current main goal is to extract this data and put it into a File::ShareDir directory, allowing the distribution to contain the files in full (not in some rat bastardized embedded form) and copy them as needed upon new application creation.  This is a big step in lending itself to a new and cleaner Catalyst::Helper API.

With this in mind, Tomas Doran wrote a test to help me determine whether or not the original application generated (before the evisceration commenced) matches the application generated with the templates and images in a share directory.

I've got code written to this effect, I now need to switch out the current _mk_foo methods respectively to reflect the new code and file distribution method.
So since my last post, I've put together a nice TODO for my project.  Hiveminder is all set up, and tasks have due dates on them.

By friday, I'd like to have my RFC completed and up to get some good feedback on my (well, our, really) plan of attack and path on which we are taking. I'm working on writing tests tonight to make sure application generation from the old API doesn't change with my progress.  Essentially, we want the same end result, just better, with an improved API to give more flexibility in getting routine bits of code done.

For starters, we'd like to get all the Template::Toolkit stuff ripped out and put into individual templates, as well as the God awful hex code that represents the binary images to be written into a new application's root/ directory.  File::ShareDir seems to be the best method for taking care of transporting those kinds of files in a distribution and sanely installing them.

I will write more once I hack on and clean up some of the tests.

Fixed! (again)

| No Comments | No TrackBacks
I'm back.

(again)

I ran into an error where templates weren't being published for individual blogs.  I googled and googled, and came up with this: http://forums.movabletype.org/2009/02/indv-entries-no-longer-published.html. Back in action!

For those of you who haven't heard. I've been accepted into Google Summer of Code.  I'll be using this blog to record my progress and document my journey.  If you're interested, read along and keep up.  It'll be an interesting adventure, I've taken on the task of refactoring the  Catalyst::Helper API which although daunting, will really launch my web developer career in a large scale aspect.

Check back soon, and check out www.catalyzed.org, an excellent resource for the Catalyst Framework and Perl in general.

Until tomorrow,

-Devin

About this Archive

This page is an archive of entries from May 2009 listed from newest to oldest.

March 2009 is the previous archive.

June 2009 is the next archive.

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