package Foo::Bar::UrlHandler;
sub new($proto, %config) {
my $class = ref($proto) || $proto;
if(!defined($config{url})) {
# No URL given, don't know what to do next
return;
}
my $self = bless \%config, $class;
return $self;
}
####
my $handler = Foo::Bar::UrlHandler->new(url => 'http://perlmonks.org')
or do_some_error_handling();
##
##
package Foo::Bar::UrlHandler;
sub new($proto, %config) {
my $class = ref($proto) || $proto;
if(!defined($config{url})) {
# No URL given, don't know what to do next
return;
}
if($config{url} =~ /^http\:/) {
return Foo::Bar::UrlHandler::HTTP->new();
} elsif($config{url} =~ /^file\:/) {
return Foo::Bar::UrlHandler::FILE->new();
}
# Invalid URL?
return;
}
##
##
sub new($proto, %config) {
my $class = ref($proto) || $proto;
# Override the default template
$config{htmltemplate} = 'righttoleft.tt';
# Call parent constructor to load and parse template
my $self = $class->SUPER::new(%config);
# Re-bless
bless $self, $class; # Re-bless with our class
$self->do_our_own_stuff();
return $self;
}