#!/usr/bin/perl
use strict;
use CGI;
use Template;
use SBL_Config;
my $q = CGI->new;
my $t = Template->new;
my $config = SBL_Config->new;
$config->check($q) || die $config->error;
print $q->header();
$t->process('index.tt', {}) || die $t->error;
####
#!/usr/bin/perl
package SBL_Config;
use strict;
use warnings;
use diagnostics;
use Data::Dumper;
my $root_url = "/sbl";
sub new {
my $self = {};
$self->{ROOT} = $root_url;
$self->{ERROR} = undef;
bless($self);
return $self;
}
sub root {
my $self = shift;
if (@_) { die "SBL_Config::root is read-only"; }
return $self->{ROOT};
}
sub error {
my $self = shift;
if (@_) { die "SBL_Config::error is read-only"; }
return $self->{ERROR};
}
sub check {
my ( $self, $q ) = @_;
# my $self = shift;
# my $q = shift;
die "No CGI query passed to SBL_Config::check" if undef $q;
print STDERR "q is " . (undef $q ? "undef" : "defined") . "\n";
print STDERR Dumper $q;
my $loc;
$loc = $q->url() || die "No URL from CGI";
$loc = $q->url(-relative=>1) || die "No relative URL from CGI";
if ($loc != $self->root ) { $self->{ERROR} = "Bad root URL"; return 0; }
return 1;
}
####
A title
A body
####
] q is defined
] $VAR1 = undef;
] Can't call method "url" on an undefined value at SBL_Config.pm line 42 (#1)
] (F) You used the syntax of a method call, but the slot filled by the
] object reference or package name contains an undefined value. Something
] like this will reproduce the error:
]
] $BADREF = undef;
] process $BADREF 1,2,3;
] $BADREF->process(1,2,3);
]
] Uncaught exception from user code:
] \tCan't call method "url" on an undefined value at SBL_Config.pm line 42.
] at SBL_Config.pm line 42
] \tSBL_Config::check('SBL_Config=HASH(0x24bd2e8)', 'CGI=HASH(0x1dcdf40)') called at /var/www/html/streetcar/index.pl line 12
] Premature end of script headers: index.pl