Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • How about a method that returns the serialiser code as a string (with selectable package name), which can then be evaled by the test file for testing?

    • I don't want to embed a string of code. I'm doing a huge amount of that already to do code generation and it makes a lot of my code hard to follow, despite aggressive refactoring. If I keep these packages in real packages, I get the benefits of my t/00-load.t test:

      #!perl

      use Test::More;
      use File::Spec::Functions 'splitdir';
      use File::Find;

      sub path_to_module {
          my $path = shift;
          $path =~ s/\.pm\z//;
          my @components = splitdir($path);
          shift @components;   # discard lib/
          return join '::' => @components;
      }

      BEGIN {
          my @packages;
          find({
              no_chdir => 1,
              wanted   => sub {
                  if ( /\.pm\z/ ) {
                     push @packages => path_to_module $File::Find::name;
                  }
              }
          }, 'lib');

          plan tests => scalar @packages;

          foreach my $package (@packages) {
              use_ok $package or BAIL_OUT("Cannot use ($package)");
          }
      }

      diag("Testing Bermuda $Bermuda::VERSION, Perl $], $^X");

      I always forget to add the modules to my load tests, to this ensures I can never forget them. Plus, I effectively get a compile-time check against the relocatable code instead of the runtime check against embedded strings of code.

      It's a trade-off, but if I can get the relocatable code bit working (and it's working on Solaris), then this is a nice win ... I think.

      • Put it in a SelfLoader module and add a method to pull out the source via the package’s DATA handle? That way you avoid all the path diddling gymnastics and it automatically works as a standalone module.