| 1 | #!perl -w | ||
| 2 | # | ||
| 3 | # CGI::Bus::Base - Base CGI::Bus SubObject Class | ||
| 4 | # | ||
| 5 | # admiral | ||
| 6 | # | ||
| 7 | # | ||
| 8 | |||
| 9 | package CGI::Bus::Base; | ||
| 10 | require 5.000; | ||
| 11 | use strict; | ||
| 12 | use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | ||
| 13 | use CGI::Bus; | ||
| 14 | use vars qw($VERSION @ISA $AUTOLOAD); | ||
| 15 | @ISA = qw(); | ||
| 16 | |||
| 17 | 1; | ||
| 18 | |||
| 19 | |||
| 20 | ####################### | ||
| 21 | |||
| 22 | |||
| 23 | sub new { | ||
| 24 | my $c=shift; | ||
| 25 | my $s ={}; | ||
| 26 | bless $s,$c; | ||
| 27 | $s =$s->initialize(@_); | ||
| 28 | $s->parent->set('-reset')->{'-' .$s->classt}=1 if $s->parent; | ||
| 29 | $s | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | sub initialize { | ||
| 34 | my $s =shift; | ||
| 35 | $s->parent(''); # cycle ref! | ||
| 36 | $s->set(@_); | ||
| 37 | $s | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | sub class { | ||
| 42 | substr($_[0], 0, index($_[0],'=')) | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | sub classt { | ||
| 47 | substr($_[0]->class, rindex($_[0],'::')+2) | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | sub parent { | ||
| 52 | scalar(@_) >1 ? ($_[0]->{'CGI::Bus'} =$_[1] ||$CGI::Bus::SELF) | ||
| 53 | : $_[0]->{'CGI::Bus'} | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub set { | ||
| 58 | return(keys(%{$_[0]})) if scalar(@_) ==1; | ||
| 59 | return($_[0]->{$_[1]}) if scalar(@_) ==2; | ||
| 60 | my ($s, %opt) =@_; | ||
| 61 | foreach my $k (keys(%opt)) { | ||
| 62 | $s->{$k} =$opt{$k}; | ||
| 63 | } | ||
| 64 | $s | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | sub AUTOLOAD { | ||
| 69 | my $s =shift; | ||
| 70 | my $m =substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); | ||
| 71 | $s->parent->$m(@_) | ||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | sub cgi { | ||
| 76 | shift->parent->{-cgi} | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | sub htmlescape { | ||
| 81 | !defined($_[1]) ? '' : shift->parent->{-cgi}->escapeHTML(@_) | ||
| 82 | } | ||
| 83 | |||
| 84 | |||
| 85 | sub urlescape { | ||
| 86 | !defined($_[1]) ? '' : shift->parent->{-cgi}->escape(@_) | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | sub param { | ||
| 91 | shift->parent->{-cgi}->param(@_) | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | sub print { | ||
| 96 | shift->parent->print(@_) | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | sub qparam { | ||
| 101 | shift->parent->qparam(@_) | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | sub DESTROY { | ||
| 106 | my $s =shift; | ||
| 107 | delete $s->{'CGI::Bus'}; | ||
| 108 | $s | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | sub lng { | ||
| 113 | $_[0]->{-lngbase} =$_[0]->parent->lngload($_[0]->class) if !$_[0]->{-lngbase}; | ||
| 114 | my $r =$_[0]->{-lngbase}; | ||
| 115 | $r = !defined($_[2]) ? $r->{$_[1]} | ||
| 116 | :!defined($r->{$_[2]}) ||!defined($r->{$_[2]}->[$_[1]]) ? $_[2] | ||
| 117 | :$r->{$_[2]}->[$_[1]]; | ||
| 118 | foreach my $e (@_[3..$#_]) { | ||
| 119 | $r =~s/\$_/$e/e; | ||
| 120 | } | ||
| 121 | $r | ||
| 122 | } | ||
| 123 | |||
| 124 |