MakeMaker support for pod2html
[p5sagit/p5-mst-13.2.git] / lib / CGI / Switch.pm
CommitLineData
54310121 1package CGI::Switch;
2use Carp;
3use strict;
4use vars qw($VERSION @Pref);
424ec8fa 5$VERSION = '0.06';
54310121 6@Pref = qw(CGI::Apache CGI); #default
7
8sub import {
9 my($self,@arg) = @_;
10 @Pref = @arg if @arg;
11}
12
13sub new {
14 shift;
15 my($file,$pack);
16 for $pack (@Pref) {
17 ($file = $pack) =~ s|::|/|g;
18 eval { require "$file.pm"; };
19 if ($@) {
20#XXX warn $@;
21 next;
22 } else {
23#XXX warn "Going to try $pack\->new\n";
24 my $obj;
25 eval {$obj = $pack->new(@_)};
26 if ($@) {
27#XXX warn $@;
28 } else {
29 return $obj;
30 }
31 }
32 }
33 Carp::croak "Couldn't load+construct any of @Pref\n";
34}
35
54310121 361;
37__END__
38
39=head1 NAME
40
41CGI::Switch - Try more than one constructors and return the first object available
42
43=head1 SYNOPSIS
44
45
46 use CGISwitch;
47
48 -or-
49
50 use CGI::Switch This, That, CGI::XA, Foo, Bar, CGI;
51
52 my $q = new CGI::Switch;
53
54=head1 DESCRIPTION
55
56Per default the new() method tries to call new() in the three packages
57Apache::CGI, CGI::XA, and CGI. It returns the first CGI object it
58succeeds with.
59
60The import method allows you to set up the default order of the
61modules to be tested.
62
63=head1 SEE ALSO
64
65perl(1), Apache(3), CGI(3), CGI::XA(3)
66
67=head1 AUTHOR
68
424ec8fa 69Andreas KE<ouml>nig E<lt>a.koenig@mind.deE<gt>
54310121 70
71=cut