Perl@PolettiX


S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
Sun, 9 May 2010

Carp::Always would have helped

Yesterday I wrote an article about Dist::Zilla and, at a certain point, I had issues with a missing Changes file, that triggered an error whose source was not evident:

~/dzilla/Sample-Module$ dzil release
[DZ] beginning to build Sample-Module
[BumpVersionFromGit] Bumping version from 0.1.3 to 0.1.4
[DZ] guessing dist's main_module is lib/Sample/Module.pm
[DZ] extracting distribution abstract from lib/Sample/Module.pm
[DZ] writing Sample-Module in Sample-Module-0.1.4
[DZ] writing archive to Sample-Module-0.1.4.tar.gz
[@Filter/Check] branch master is in a clean state
[@Filter/TestRelease] ...
...
[@Filter/TestRelease] all's well; removing .build/OIeyjyhBZd
[FakeRelease] Fake release happening (nothing was really done)
can't open Changes for reading: No such file or directory\
 at /opt/perl-5.8.8/lib/site_perl/5.8.8/Dist/Zilla/File/OnDisk.pm line 31.
To find out the offending plugin I decided to hack Dist::Zilla::File::OnDisk, turning a die() into a Carp::confess() to see what was going wrong:
--- src.OnDisk.pm
+++ dst.OnDisk.pm
@@ -28,7 +28,8 @@
 sub _read_file {
   my ($self) = @_;
 
   my $fname = $self->_original_name;
-  open my $fh, '<', $fname or die "can't open $fname for reading: $!";
+  use Carp;
+  open my $fh, '<', $fname or Carp::confess "can't open $fname for reading: $!";
   my $content = do { local $/; <$fh> };
 }

Had I read the title of Tokuhiro Matsuno's post Carp::Always::Color (well, I can't read Japanese, so I can't go beyond an English title!), I would have avoided all the editing mess to just use Adriano Ferreira's Carp::Always.

So, instead of editing the file, I should have find out where dzil is installed in my system:

~/dzilla/Sample-Module$ which dzil
/opt/perl/bin/dzil
This way, the perl executable can be called directly to add Carp::Always in the command line:
~/dzilla/Sample-Module$ perl -MCarp::Always /opt/perl/bin/dzil release
[DZ] beginning to build Sample-Module
[BumpVersionFromGit] Bumping version from 0.1.3 to 0.1.4
[DZ] guessing dist's main_module is lib/Sample/Module.pm
[DZ] extracting distribution abstract from lib/Sample/Module.pm
[DZ] writing Sample-Module in Sample-Module-0.1.4
[DZ] writing archive to Sample-Module-0.1.4.tar.gz
[@Filter/Check] branch master is in a clean state
[@Filter/TestRelease] ...
...
[@Filter/TestRelease] all's well; removing .build/dE1qIIQWEG
[FakeRelease] Fake release happening (nothing was really done)
can't open Changes for reading: No such file or directory\
 at /opt/perl-5.8.8/lib/site_perl/5.8.8/Dist/Zilla/File/OnDisk.pm line 31
   Dist::Zilla::File::OnDisk::_read_file(...
   Dist::Zilla::File::OnDisk::__ANON__(...
   Class::MOP::Attribute::default(...
   Dist::Zilla::File::OnDisk::content(...
   Dist::Zilla::Plugin::Git::Commit::_get_changes(...
   Dist::Zilla::Plugin::Git::Commit::__ANON__(...
   String::Formatter::method_replace(...
   String::Formatter::format(...
   String::Formatter::__ANON__(...
   Dist::Zilla::Plugin::Git::Commit::get_commit_message(...
   Dist::Zilla::Plugin::Git::Commit::after_release(...
   Dist::Zilla::release(...
   Dist::Zilla::App::Command::release::execute(...
   App::Cmd::execute_command(...
   App::Cmd::run(...

VoilĂ , a perfect stack trace with the info I was after!

Posted at 14:45:40 by Flavio Poletti