Ok, I'm kinda new to perl and I would like to know how I would go about debugging code when using Apache.
I was just looking at the error.log for apache but once I got all the errors sorted apache just segfaults when I try to run my script.
How do I find out what is going on? (I dont think it's apache because I tested individual bits of code as I went and my problems only started when I tried to make them all work together)
Here is the code:
#!/usr/bin/perl -w
# Woot! The second version.
$VERSION = 0.02;
# like a good little coder
use strict;
# required modules
use Apache;
use XML::DOM;
use HTML::Template;
use vars qw($parsed_xml);
# move this sort of stuff to a .conf file later
my $xml_file = '/home/iordy/perl.iordy.net/iXML_base.xml';
# Read and parse the document
my $parser = XML::DOM::Parser->new();
$parsed_xml = $parser->parsefile ($xml_file);
## main ##
# &process_args(); #process arguments and move on from there.
my $page_content = "page content";
&showpage($page_content);
## subs ##
sub search {
my ($search_for_section) = @_;
my @search_section_results;
foreach my $node ($parsed_xml->getElementsByTagName('section_id')){
if ($node->getAttibute('section_name') eq $search_for_section) {
push @search_section_results,$node->getAttribute('section_id');
}
}
return @search_section_results;
}
sub process_args {
my $r = Apache->request;
my %arguments = $r->args;
my $page_content;
foreach my $key (keys %arguments) {
my $arg = $arguments{$key};
#swap this to a switch later?
if ($arg eq 'search') {
foreach my $search_result (&search($arg)){
$page_content .= $search_result . "<br />";
}
}
else{
$page_content = "Page Error: No valid argument specified!";
}
}
&showpage($page_content);
}
# note: make this a package later on, plus add in all the other attrib
+utes that a page will need.
sub showpage {
my ($page_content) = @_;
my $r = Apache->request;
$r->send_http_header('text/html');
$r->print($page_content);
}
And here is the xml:
<xml>
<section section_id=1 section_name="root" section_title="iordy.com ->
+root">
<page_content>
<page>root.html</page>
</page_content>
</section>
<section section_id=2 section_name="art" section_title="iordy.com -> a
+rt">
<page_content>
<page>art.html</page>
<page page_title="iordy.com -> art.2">art2.html</page>
</page_content>
</section>
<section section_id=3 section_name="test" section_title="iordy.com ->
+subtree test">
<page_content>
<page page_title="iordy.com -> subtree test page1">test1.html</page>
<page page_title="iordy.com -> subtree test page2">test2.html</page>
</page_content>
<section section_id=4 section_name="test3" section_title="iordy.com -
+> subtree test2">
<page_content>
<page page_title="iordy.com -> subtree test page 3">test3.html</pag
+e>
</page_content>
</section>
</section>
</xml>