Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How's My Style Now?

by scorpio17 (Canon)
on Feb 08, 2010 at 15:19 UTC ( [id://822033]=note: print w/replies, xml ) Need Help??


in reply to How's My Style Now?

You might consider using CGI::Application and HTML::Template. Note that templates can contain other templates, so you can have a single, top-level template that pulls in templates for things like header, footer, main panel, left panel, etc. Then the CGI script simply builds up a hash of all the data, and sends it to the template. The benefit is that you remove virtually all of the HTML related stuff from your script, and you can change the entire layout of your site by simply editing the template files (which are like html files with place holders for the data).

Replies are listed 'Best First'.
Re^2: How's My Style Now?
by Spenser (Friar) on Mar 14, 2010 at 12:28 UTC

    As a follow-up to my original post, below is how the code for that same program looks now. I'm posting it here in case someone else wants to convert to modules and want to see how that would look. Thanks again for all of the advice everyone gave me. I'm still incorporating your ideas.

    #!/usr/bin/perl # program name: musings.cgi # set libraries, scripts, & paths use strict; use warnings; use library::core; use library::musings; use CGI qw(:standard); my $scripts = core::get_script_variables(); my $script = $scripts->{'musing'}->{'script'}; my $top_script = $scripts->{'musings'}->{'script'}; # capture user input my $musing_id = param('musing_id') || ''; my $ref_id = param('ref_id') || ''; # check if user data is complete if($musing_id =~ m|\d|g) { print redirect($script . '?musing_id=' . $musing_id); exit; } # get general text for web page my $general_text = core::get_general_text('musings',1); my ($page_heading,$page_text,$page_image) = @{$general_text->[0]}; my $n = "\015\012"; # get web log entry my $entries = musings::get_musings_entries($ref_id); my $comments_cnt = musings::get_comments_cnt(); my $musing_stats = musings::get_reader_stats(); my $musing_cats = musings::get_musings_cats(); # alter heading if musing category selected if($ref_id) { $general_text = core::get_general_text('musings_category',1); ($page_heading,$page_text,$page_image) = @{$general_text->[0]}; $page_heading = ucfirst($musing_cats->{$ref_id}->{'ref_name'}) . $p +age_heading; } # web page core::heading($page_heading,undef,$page_text); core::panel_start(1); core::fiction(); core::miscellany(); core::musings_sites(); core::panel_end(); core::panel_start(2); core::page_heading($page_heading,$page_text,undef); # display musing entries foreach (@$entries) { my ($id, $ref_id, $log_head, $entry, $entry_date) = @$_; my $cat = lc($musing_cats->{$ref_id}->{'ref_name'}); my $cnt = $comments_cnt->{$id}->{'comments_cnt'} || 'no'; my $reader_stat = $musing_stats->{$id}->{'stat'}; $entry_date = lc($entry_date); print div({class=>'content_item'}, $n, div({class=>'musing_abstract'}, $n, h3(a({href=>$script . '?musing_id=' . $id}, $log_head) ), $n, span($entry), $n ), $n, div({class=>'item_stats'}, $n, 'posted:', $entry_date, '; readers: ', $reader_stat, '; ', $n, a({id=>'cmt_note', href=>$script . '?musing_id=' . $id}, $cnt, 'comments'), $n, 'category: ', a({id=>'cmt_note', href=>$top_script . '?ref_id=' . $ref_id}, $cat) ), $n ), $n; } core::panel_end(); core::panel_start(3); core::display_page_image($page_image); musings::get_display_category_data(); core::stats_musings(); core::panel_end(); core::footer(); exit;

    -Spenser

    That's Spenser, with an "s" like the detective.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found