David Bushong
Résumé
Picture Gallery
Software Tidbits
Links
Contact Me

Software Tidbits

#!/usr/local/bin/perl

## load in dependencies
use strict;
use HTML::Mason::Compiler::ToObject;
use File::Temp;

## usage
die "usage: $0 mason-component\n" unless @ARGV == 1 && $ARGV[0] !~ /^-/;
my $file = $ARGV[0];

## read in the component
open(my $fh, '<', $file) || die "$0: couldn't open comp $file: $!\n";
my $src  = do { local $/; <> };
close($fh);

## do the component parsing
my $c = HTML::Mason::Compiler::ToObject->new(
  default_escape_flags    => 'h',
  use_source_line_numbers => 1,
);
my $code = $c->compile(comp_source => \$src, name => $file);

## create a tmpfile and write the parsed perl to it
my ($fh, $tmp) = File::Temp::tempfile('/tmp/masoncheck.XXXX');
print $fh "my \$r;\n";
print $fh ($$code);
close($fh);

## syntax check the perl
system($^X, '-cw', $tmp);

## cleanup the tmpfile
unlink($tmp);