Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.2 KiB

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