Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

HTML::Mason

by set_uk (Pilgrim)
on Apr 12, 2003 at 12:57 UTC ( [id://250051]=perlquestion: print w/replies, xml ) Need Help??

set_uk has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: HTML::Mason
by IlyaM (Parson) on Apr 12, 2003 at 13:51 UTC
    Paths to components are always relative to component root. If your component root is /foo/bar and your component path is /foo/bar than it corresponds to file /foo/bar/foo/bar. It seems that Mason treats this situation as error (as it is very unlickely that a component root is same as a component path) so it produces this error.

    Solution: if you want to use a component paths which match filenames use component root == '/' (BTW I think it is default when you use HTML::Mason in standalone mode but I'm not sure). Or set component root to something else and use correct component paths.

    --
    Ilya Martynov, ilya@iponweb.net
    CTO IPonWEB (UK) Ltd
    Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
    Personal website - http://martynov.org

      Tried that and it then complains saying it cant find the components from / as follows:-
      could not find component for path '/lib/header.mas' 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:967] [/export/home/set/scripts/perl/site_build/base_dir/htdocs/reviews/au +tohandler:9] 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'm assuming that this just doesn't work out of the box as a good example.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://250051]
Approved by silent11
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-23 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found