I need to auto-generate a mostly static HTML site and I am trying to get to grips with HTML::Mason and the example they give in the handbook.
When I run the following code:-
#!/usr/bin/perl -w
use strict; # Always use strict!
use Cwd;
use File::Basename;
use File::Find;
use File::Path;
use File::Spec;
use HTML::Mason;
# These are directories. The canonpath method removes any cruft
# like doubled slashes.
my ($source, $target) = map { File::Spec->canonpath($_) } @ARGV;
die "Need a source and target\n"
unless defined $source && defined $target;
# Make target absolute because File::Find changes the current workin
+g
# directory as it runs.
$target = File::Spec->rel2abs($target);
my $interp =
#HTML::Mason::Interp->new( comp_root => '/export/home/set/script
+s/perl/site_build/base_dir/lib' );
HTML::Mason::Interp->new( comp_root => File::Spec->rel2abs(cwd)
+);
find( \&convert, $source );
sub convert {
# We don't want to try to convert our autohandler or .mas
# components. $_ contains the filename
return unless /\.html$/;
my $buffer;
# This will save the component's output in $buffer
$interp->out_method(\$buffer);
# We want to split the path to the file into its components and
# join them back together with a forward slash in order to make
# a component path for Mason
#
# $File::Find::name has the path to the file we are looking at,
# relative to the starting directory
my $comp_path = join '/', File::Spec->splitdir($File::Find::name
+);
$interp->exec("/$comp_path");
# Strip off leading part of path that matches source directory
my $name = $File::Find::name;
$name =~ s/^$source//;
# Generate absolute path to output file
my $out_file = File::Spec->catfile( $target, $name );
# In case the directory doesn't exist, we make it
mkpath(dirname($out_file));
local *RESULT;
open RESULT, "> $out_file" or die "Cannot write to $out_file: $!
+";
print RESULT $buffer or die "Cannot write to $out_file: $!";
close RESULT or die "Cannot close $out_file: $!";
}
With the following parameters:-
./gen* /export/home/set/scripts/perl/site_build/base_dir/htdocs/review
+s /tmp
I get the following error:-
Your component path (/export/home/set/scripts/perl/site_build/base_dir
+/htdocs/reviews/test.html) matches a real file on disk (/export/home/
+set/scripts/perl/site_build/base_dir/htdocs/reviews/test.html). Have
+ you read about the component root in the Administrator's Manual (HTM
+L::Mason::Admin)? at /usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/
+Resolver/File.pm line 91.
could not find component for initial path '/export/home/set/scripts/pe
+rl/site_build/base_dir/htdocs/reviews/test.html'
Stack:
[/usr/local/lib/perl5/site_perl/5.8.0/Exception/Class.pm:153]
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Request.pm:226]
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Request.pm:166]
[/usr/local/lib/perl5/site_perl/5.8.0/Class/Container.pm:265]
[/usr/local/lib/perl5/site_perl/5.8.0/Class/Container.pm:343]
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Interp.pm:232]
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Interp.pm:226]
[./generate_html.pl:46]
[/usr/local/lib/perl5/5.8.0/File/Find.pm:849]
[/usr/local/lib/perl5/5.8.0/File/Find.pm:666]
[/usr/local/lib/perl5/5.8.0/File/Find.pm:1160]
[./generate_html.pl:27]
Stack:
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Request.pm:281]
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Request.pm:385]
[/usr/local/lib/perl5/site_perl/5.8.0/HTML/Mason/Request.pm:351]
I dont know enough yet to identify what the issue is - but as I am running it out of the box as it were I thought others might also have had the same issue and could point me in the right direction.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.