Wombat/Connector/RequestBase.pm untested

filter: Statementstmt 0.0% 0 / 271 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 71 Podpod 0.0% 0 / 58 totaltotal 0.0% 0 / 463 CC 22 SCAR 16.7
CC
22
Cov
0%
getReader
20.0
getRequestDispatcher
20.0
getLocales
12.0
CRAP 5.3
1 # -*- Mode: Perl; indent-tabs-mode: nil; -*-
2  
3 package Wombat::Connector::RequestBase;
4  
5 =pod
6  
7 =head1 NAME
8  
9 Wombat::Connector::RequestBase - internal request base class
10  
11 =head1 SYNOPSIS
12  
13 package My::Connector::Request;
14  
15 use base qw(Wombat::Connector::RequestBase);
16  
17 =head1 DESCRIPTION
18  
19 Convenience base implementation of B<Wombat::Request> and
20 B<Servlet::ServletRequest> which can be used for most connectors. Only
21 connector-specific methods need to be implemented.
22  
23 =cut
24  
25 use base qw(Wombat::Request);
26 use fields qw(application authorization connector facade handle response);
27 use fields qw(socket wrapper attributes characterEncoding contentLength);
28 use fields qw(contentType defaultLocale input locales parameters protocol);
29 use fields qw(reader remoteAddr remoteHost scheme serverName serverPort);
30 use fields qw(secure);
31 use strict;
32 use warnings;
33  
34 use Servlet::Util::Exception ();
35 use Wombat::Connector::RequestFacade ();
36 use Wombat::Connector::RequestHandle ();
37 use Wombat::Globals ();
38 use Wombat::Util::RequestUtil ();
39  
40 =pod
41  
42 =head1 CONSTRUCTOR
43  
44 =over
45  
46 =item new()
47  
48 Construct and return a B<Wombat::Connector::RequestBase> instance,
49 initializing fields appropriately. If subclasses override the
50 constructor, they must be sure to call
51  
52 $self->SUPER::new();
53  
54 =back
55  
56 =cut
57  
58 sub new {
59 my $self = shift;
60 my $facade = shift;
61  
62 $self = fields::new($self) unless ref $self;
63  
64 $self->recycle($facade);
65  
66 return $self;
67 }
68  
69 =pod
70  
71 =head1 ACCESSOR METHODS
72  
73 =over
74  
75 =item getApplication()
76  
77 Return the Application within which this request is being processed.
78  
79 =cut
80  
81 sub getApplication {
82 my $self = shift;
83  
84 return $self->{application};
85 }
86  
87 =pod
88  
89 =item setApplication($application)
90  
91 Set the Application within which this request is being processed. This
92 must be called as soon as the appropriate Application is identified,
93 because it enables parsing of the request URI.
94  
95 B<Parameters:>
96  
97 =over
98  
99 =item $application
100  
101 the B<Wombat::Application> within which the request is being processed
102  
103 =back
104  
105 =cut
106  
107 sub setApplication {
108 my $self = shift;
109 my $application = shift;
110  
111 $self->{application} = $application;
112  
113 return 1;
114 }
115  
116 =pod
117  
118 =item getAttribute($name)
119  
120 Return the value of the named attribute.
121  
122 B<Parameters:>
123  
124 =over
125  
126 =item $name
127  
128 the name of the attribute
129  
130 =back
131  
132 =cut
133  
134 sub getAttribute {
135 my $self = shift;
136 my $name = shift;
137  
138 return $self->{attributes}->{$name};
139 }
140  
141 =pod
142  
143 =item getAttributeNames()
144  
145 Return an array containing the names of the attributes available to
146 this request.
147  
148 =cut
149  
150 sub getAttributeNames {
151 my $self = shift;
152  
153 my @attributes = keys %{ $self->{attributes} };
154  
155 return wantarray ? @attributes : \@attributes;
156 }
157  
158 =pod
159  
160 =item removeAttribute($name)
161  
162 Remove the named attribute from this request.
163  
164 B<Parameters:>
165  
166 =over
167  
168 =item $name
169  
170 the name of the attribute
171  
172 =back
173  
174 =cut
175  
176 sub removeAttribute {
177 my $self = shift;
178 my $name = shift;
179  
180 delete $self->{attributes}->{$name};
181  
182 return 1;
183 }
184  
185 =pod
186  
187 =item setAttribute($name, $value)
188  
189 Set the named attribute in this request.
190  
191 B<Parameters:>
192  
193 =over
194  
195 =item $name
196  
197 the name of the attribute
198  
199 =item $value
200  
201 the value to be set, a scalar or a reference
202  
203 =back
204  
205 =cut
206  
207 sub setAttribute {
208 my $self = shift;
209 my $name = shift;
210 my $value = shift;
211  
212 $self->{attributes}->{$name} = $value;
213  
214 return 1;
215 }
216  
217 =pod
218  
219 =item getAuthorization()
220  
221 Return the authorization credentials sent with this request.
222  
223 =cut
224  
225 sub getAuthorization {
226 my $self = shift;
227  
228 return $self->{authorization};
229 }
230  
231 =pod
232  
233 =item setAuthorization($authorization)
234  
235 Sets the authorization credentials sent with this request.
236  
237 B<Parameters:>
238  
239 =over
240  
241 =item $authorization
242  
243 the authorization credentials
244  
245 =back
246  
247 =cut
248  
249 sub setAuthorization {
250 my $self = shift;
251 my $authorization = shift;
252  
253 $self->{authorization} = $authorization;
254  
255 return 1;
256 }
257  
258 =pod
259  
260 =item getCharacterEncoding()
261  
262 Return the name of the character encoding used in the body of this
263 request.
264  
265 =cut
266  
267 sub getCharacterEncoding {
268 my $self = shift;
269  
270 return $self->{characterEncoding};
271 }
272  
273 =pod
274  
275 =item setCharacterEncoding($name)
276  
277 Set the name of the character encoding used for the body of this
278 request. This method must be called prior to reading request
279 parameters or reading input using C<getReader()>.
280  
281 B<Parameters:>
282  
283 =over
284  
285 =item $name
286  
287 the name of the encoding
288  
289 =back
290  
291 B<Throws:>
292  
293 =over
294  
295 =item B<Servlet::Util::UnsupportedEncodingException>
296  
297 if this is not a valid encoding
298  
299 =back
300  
301 =cut
302  
303 sub setCharacterEncoding {
304 my $self = shift;
305 my $enc = shift;
306  
307 $self->{characterEncoding} = $enc;
308  
309 return 1;
310 }
311  
312 =pod
313  
314 =item getConnector()
315  
316 Return the Connector through which this request was received.
317  
318 =cut
319  
320 sub getConnector {
321 my $self = shift;
322  
323 return $self->{connector};
324 }
325  
326 =pod
327  
328 =item setConnector($connector)
329  
330 Set the Connector through which this request was received.
331  
332 B<Parameters:>
333  
334 =over
335  
336 =item $connector
337  
338 the B<Wombat::Connector> that received the request
339  
340 =back
341  
342 =cut
343  
344 sub setConnector {
345 my $self = shift;
346 my $connector = shift;
347  
348 $self->{connector} = $connector;
349  
350 return 1;
351 }
352  
353 =pod
354  
355 =item getContentLength()
356  
357 Return the content length, in bytes, of the request body provided by
358 the input handle.
359  
360 =cut
361  
362 sub getContentLength {
363 my $self = shift;
364  
365 return $self->{contentLength};
366 }
367  
368 =pod
369  
370 =item setContentLength($length)
371  
372 Set the length, in bytes, of the request body provided by the input
373 handle.
374  
375 B<Parameters:>
376  
377 =over
378  
379 =item $length
380  
381 the content length in bytes
382  
383 =back
384  
385 =cut
386  
387 sub setContentLength {
388 my $self = shift;
389 my $length = shift;
390  
391 $self->{contentLength} = $length;
392  
393 return 1;
394 }
395  
396 =pod
397  
398 =item getContentType()
399  
400 Return the MIME type of the body of the request.
401  
402 =cut
403  
404 sub getContentType {
405 my $self = shift;
406  
407 return $self->{contentType};
408 }
409  
410 =pod
411  
412 =item setContentType($type)
413  
414 Set the MIME type of the body of this Request. If the C<charset> parameter is
415 specified, the character encoding of this Request is also set.
416  
417 B<Parameters:>
418  
419 =over
420  
421 =item $type
422  
423 the MIME type
424  
425 =back
426  
427 =cut
428  
429 sub setContentType {
430 my $self = shift;
431 my $type = shift;
432  
433 $self->{contentType} = $type;
434 my $charset = Wombat::Util::RequestUtil->parseCharacterEncoding($type);
435 $self->{characterEncoding} = $charset if $charset;
436  
437 return 1;
438 }
439  
440 =pod
441  
442 =item getHandle()
443  
444 Return the underlying input handle associated with this
445 request. Usually the Socket and Handle for the request are the same
446 object, but this is not required.
447  
448 =cut
449  
450 sub getHandle {
451 my $self = shift;
452  
453 return $self->{handle};
454 }
455  
456 =pod
457  
458 =item setHandle($handle)
459  
460 Set the input handle ssociated with this request.
461  
462 B<Parameters:>
463  
464 =over
465  
466 =item $handle
467  
468 the B<IO::Handle> associated with this request
469  
470 =back
471  
472 =cut
473  
474 sub setHandle {
475 my $self = shift;
476 my $handle = shift;
477  
478 $self->{handle} = $handle;
479 }
480  
481 =pod
482  
483 =item getInputHandle()
484  
485 Return the B<Servlet::ServletInputHandle> that wraps the underlying
486 input handle (see C<getHandle()>. The default implementation returns a
487 handle created by C<createInputHandle()>.
488  
489 B<Throws:>
490  
491 =over
492  
493 =item B<Servlet::Util::IllegalStateException>
494  
495 if C<getReader()> has already been called for this request
496  
497 =item B<Servlet::Util::IOException>
498  
499 if an input or output exception occurred
500  
501 =back
502  
503 =cut
504  
505 sub getInputHandle {
506 my $self = shift;
507  
508 if ($self->{reader}) {
509 my $msg = "getInputHandle: reader already obtained";
510 Servlet::Util::IllegalStateException->throw($msg);
511 }
512  
513 $self->{input} ||= $self->createInputHandle();
514  
515 return $self->{input};
516 }
517  
518 =pod
519  
520 =item getLocale()
521  
522 Return the preferred locale that the client will accept content in,
523 based on the value for the first I<Accept-Language> header that was
524 encountered. If the request did not specify a preferred language, the
525 server's default locale is returned.
526  
527 =cut
528  
529 sub getLocale {
530 my $self = shift;
531  
532 return $self->{locales}->[0] || $self->{defaultLocale};
533 }
534  
535 =pod
536  
537 =item getLocales()
538  
539 Return the set of preferred locales specified by the client, based on
540 the values for any I<Accept-Language> headers that were
541 encountered. If the request did not specify a preferred language, the
542 server's default locale is returned.
543  
544 =cut
545  
546 sub getLocales {
547 my $self = shift;
548  
549 my @locs = @{ $self->{locales} };
550 push @locs, $self->{defaultLocale} unless @locs;
551  
552 return wantarray ? @locs : \@locs;
553 }
554  
555 =pod
556  
557 =item addLocale($loc)
558  
559 Add a locale to the set of preferred Locales for this Request.
560  
561 B<Parameters:>
562  
563 =over
564  
565 =item $loc
566  
567 the locale to add
568  
569 =back
570  
571 =cut
572  
573 sub addLocale {
574 my $self = shift;
575 my $loc = shift;
576  
577 push @{ $self->{locales} }, $loc;
578  
579 return 1;
580 }
581  
582 =pod
583  
584 =item clearLocales()
585  
586 Clear the list of locales for this Request.
587  
588 =cut
589  
590 sub clearLocales {
591 my $self = shift;
592  
593 $self->{locales} = [];
594  
595 return 1;
596 }
597  
598 =pod
599  
600 =item getParameter($name)
601  
602 Return the value of the named request parameter. If more than one
603 value is defined, return only the first one.
604  
605 B<Parameters:>
606  
607 =over
608  
609 =item $name
610  
611 the name of the parameter
612  
613 =back
614  
615 =cut
616  
617 sub getParameter {
618 my $self = shift;
619 my $name = shift;
620  
621 my $param = $self->{parameters}->{$name};
622  
623 return defined $param ? $param->[0] : '';
624 }
625  
626 =pod
627  
628 =item getParameterMap()
629  
630 Return a hash of the parameters of this Request. The keys of the hash
631 are the parameter names, and the values of the hash are arrays of
632 parameter values.
633  
634 =cut
635  
636 sub getParameterMap {
637 my $self = shift;
638  
639 my %params;
640 for my $name ($self->getParameterNames()) {
641 $params{$name} = $self->getParameterValues($name);
642 }
643  
644 return wantarray ? %params : \%params;
645 }
646  
647 =pod
648  
649 =item getParameterNames()
650  
651 Return an array containing the names of the parameters contained in
652 this Request.
653  
654 =cut
655  
656 sub getParameterNames {
657 my $self = shift;
658  
659 my @names = keys %{ $self->{parameters} };
660  
661 return wantarray ? @names : \@names;
662 }
663  
664 =pod
665  
666 =item getParameterValues($name)
667  
668 Return an array containing all of the values of the named request
669 parameter.
670  
671 B<Parameters:>
672  
673 =over
674  
675 =item $name
676  
677 the name of the parameter
678  
679 =back
680  
681 =cut
682  
683 sub getParameterValues {
684 my $self = shift;
685 my $name = shift;
686  
687 my @vals;
688 my $param = $self->{parameters}->{$name};
689 push @vals, @$param if defined $param;
690  
691 return wantarray ? @vals : \@vals;
692 }
693  
694 =pod
695  
696 =item addParameter($name, @values)
697  
698 Add a named parameter with one or more values to this Request.
699  
700 B<Parameters:>
701  
702 =over
703  
704 =item $name
705  
706 the name of the parameter to add
707  
708 =item @values
709  
710 a list of one or more parameter values, scalar or C<undef>
711  
712 =back
713  
714 =cut
715  
716 sub addParameter {
717 my $self = shift;
718 my $name = shift;
719  
720 $self->{parameters}->{$name} ||= [];
721  
722 push @{ $self->{parameters}->{$name} }, @_;
723  
724 return 1;
725 }
726  
727 =pod
728  
729 =item clearParameters()
730  
731 Clear the set of parameters for this Request.
732  
733 =cut
734  
735 sub clearParameters {
736 my $self = shift;
737  
738 $self->{parameters} = {};
739  
740 return 1;
741 }
742  
743 =pod
744  
745 =item getProtocol()
746  
747 Return the name and version of the protocol used for the request.
748  
749 =cut
750  
751 sub getProtocol {
752 my $self = shift;
753  
754 return $self->{protocol};
755 }
756  
757 =pod
758  
759 =item setProtocol($protocol)
760  
761 Set the name and version of the protocol used for the request in the
762 form I<protocol/majorVersion.minorVersion>.
763  
764 B<Parameters:>
765  
766 =over
767  
768 =item $protocol
769  
770 the name and version of the protocol
771  
772 =back
773  
774 =cut
775  
776 sub setProtocol {
777 my $self = shift;
778 my $protocol = shift;
779  
780 $self->{protocol} = $protocol;
781  
782 return 1;
783 }
784  
785 =pod
786  
787 =item getReader()
788  
789 Return the B<XXX> that wraps the ServletInputHandle for this request
790 (see C<getInputHandle()>. The default implementation returns a
791 B<XXX> wrapped around handle created by C<createInputHandle()>.
792  
793 B<Throws:>
794  
795 =over
796  
797 =item B<Servlet::Util::UnsupportedEncodingException>
798  
799 if the character encoding used is not supported and the text cannot be
800 decoded
801  
802 =item B<Servlet::Util::IllegalStateException>
803  
804 if C<getInputHandle()> has already been called for this request
805  
806 =item B<Servlet::Util::IOException>
807  
808 if an input or output exception occurred
809  
810 =back
811  
812 =cut
813  
814 sub getReader {
815 my $self = shift;
816  
817 return $self->{reader} if $self->{reader};
818  
819 if ($self->{input}) {
820 my $msg = "getReader: output handle already obtained";
821 Servlet::Util::IllegalStateException->throw($msg);
822 }
823  
824 my $encoding = $self->getCharacterEncoding() || 'ISO-8859-1';
825  
826 # XXX: how to know if an encoding is supported?
827 unless (uc $encoding eq 'ISO-8859-1') {
828 my $msg = "getReader: unsupported character encoding [$encoding]";
829 Servlet::Util::UnsupportedEncodingException->throw($msg);
830 }
831  
832 # XXX: wrap reader class around this handle
833 $self->{reader} = $self->createInputHandle();
834  
835 return $self->{reader};
836 }
837  
838 =pod
839  
840 =item getRemoteAddr()
841  
842 Return the remote IP address of the client making this request.
843  
844 =cut
845  
846 sub getRemoteAddr {
847 my $self = shift;
848  
849 return $self->{remoteAddr};
850 }
851  
852 =pod
853  
854 =item setRemoteAddr($addr)
855  
856 Set the remote IP address of the client making this request. This
857 value will be used to resolve the name of the remote host if necessary
858 (see C<getRemoteHost()>).
859  
860 B<Parameters:>
861  
862 =over
863  
864 =item $addr
865  
866 the remote IP address
867  
868 =back
869  
870 =cut
871  
872 sub setRemoteAddr {
873 my $self = shift;
874 my $remote = shift;
875  
876 $self->{remoteAddr} = $remote;
877  
878 return 1;
879 }
880  
881 =pod
882  
883 =item getRemoteHost()
884  
885 Return the remote host name of the client making this request.
886  
887 =cut
888  
889 sub getRemoteHost {
890 my $self = shift;
891  
892 return $self->{remoteHost};
893 }
894  
895 =pod
896  
897 =item setRemoteHost($host)
898  
899 Set the remote host name of the client making this request.
900  
901 B<Parameters:>
902  
903 =over
904  
905 =item $host
906  
907 the remote host name
908  
909 =back
910  
911 =cut
912  
913 sub setRemoteHost {
914 my $self = shift;
915 my $host = shift;
916  
917 $self->{remoteHost} = $host;
918  
919 return 1;
920 }
921  
922 =pod
923  
924 =item getRequest()
925  
926 Return the ServletRequest for which this object is the facade.
927  
928 =cut
929  
930 sub getRequest {
931 my $self = shift;
932  
933 return $self->{facade};
934 }
935  
936 =pod
937  
938 =item getRequestDispatcher($path)
939  
940 Return a B<Servlet::RequestDispatcher> object that acts as a wrapper
941 for the resource located at the given path. The path may be absolute
942 (relative to the context path) or relative to the current request URI.
943  
944 B<Parameters:>
945  
946 =over
947  
948 =item I<$path>
949  
950 The path to the resource
951  
952 =back
953  
954 =cut
955  
956 sub getRequestDispatcher {
957 my $self = shift;
958 my $path = shift;
959  
960 return undef unless $self->{application};
961 return undef unless defined $path;
962  
963 if ($path !~ m|^/|) {
964 # XXX convert request-relative path to context-relative path
965 }
966  
967 my $context = $self->{application}->getServletContext();
968 return $context->getRequestDispatcher($path);
969 }
970  
971 =pod
972  
973 =item getResponse()
974  
975 Return the Response with which this request is associated.
976  
977 =cut
978  
979 sub getResponse {
980 my $self = shift;
981  
982 return $self->{response};
983 }
984  
985 =pod
986  
987 =item setResponse()
988  
989 Set the Response with which this request is associated.
990  
991 B<Parameters:>
992  
993 =over
994  
995 =item $response
996  
997 the B<Wombat::Response> with which this request is associated
998  
999 =back
1000  
1001 =cut
1002  
1003 sub setResponse {
1004 my $self = shift;
1005 my $response = shift;
1006  
1007 $self->{response} = $response;
1008 }
1009  
1010 =pod
1011  
1012 =item getScheme()
1013  
1014 Return the name of the scheme used to make this request.
1015  
1016 =cut
1017  
1018 sub getScheme {
1019 my $self = shift;
1020  
1021 return $self->{scheme};
1022 }
1023  
1024 =pod
1025  
1026 =item setScheme($scheme)
1027  
1028 Set the name of the scheme used to make this request, for example
1029 I<http>, I<https>, or I<ftp>.
1030  
1031 B<Parameters:>
1032  
1033 =over
1034  
1035 =item $scheme
1036  
1037 the name of the scheme
1038  
1039 =back
1040  
1041 =cut
1042  
1043 sub setScheme {
1044 my $self = shift;
1045 my $scheme = shift;
1046  
1047 $self->{scheme} = $scheme;
1048  
1049 return 1;
1050 }
1051  
1052 =pod
1053  
1054 =item isSecure()
1055  
1056 Return a flag indicating whether or not this request was made using a
1057 secure channel.
1058  
1059 =cut
1060  
1061 sub isSecure {
1062 my $self = shift;
1063  
1064 return $self->{secure};
1065 }
1066  
1067 =pod
1068  
1069 =item setSecure($flag)
1070  
1071 Set a flag indicating whether or not the request was made using a
1072 secure channel.
1073  
1074 B<Parameters:>
1075  
1076 =over
1077  
1078 =item $flag
1079  
1080 a boolean value
1081  
1082 =back
1083  
1084 =cut
1085  
1086 sub setSecure {
1087 my $self = shift;
1088 my $secure = shift;
1089  
1090 $self->{secure} = $secure;
1091  
1092 return 1;
1093 }
1094  
1095 =pod
1096  
1097 =item getServerName()
1098  
1099 Return the host name of the server which received this request.
1100  
1101 =cut
1102  
1103 sub getServerName {
1104 my $self = shift;
1105  
1106 return $self->{serverName};
1107 }
1108  
1109 =pod
1110  
1111 =item setServerName($name)
1112  
1113 Set the host name of the server which received this request.
1114  
1115 B<Parameters:>
1116  
1117 =over
1118  
1119 =item $name
1120  
1121 the host name
1122  
1123 =back
1124  
1125 =cut
1126  
1127 sub setServerName {
1128 my $self = shift;
1129 my $name = shift;
1130  
1131 $self->{serverName} = $name;
1132  
1133 return 1;
1134 }
1135  
1136 =pod
1137  
1138 =item getServerPort()
1139  
1140 Return the port number on which this request was received.
1141  
1142 =cut
1143  
1144 sub getServerPort {
1145 my $self = shift;
1146  
1147 return $self->{serverPort};
1148 }
1149  
1150 =pod
1151  
1152 =item setServerPort($port)
1153  
1154 Set the port number on which this request was received.
1155  
1156 B<Parameters:>
1157  
1158 =over
1159  
1160 =item $port
1161  
1162 the port number
1163  
1164 =back
1165  
1166 =cut
1167  
1168 sub setServerPort {
1169 my $self = shift;
1170 my $port = shift;
1171  
1172 $self->{serverPort} = $port;
1173  
1174 return 1;
1175 }
1176  
1177 =pod
1178  
1179 =item getSocket()
1180  
1181 Return the Socket (if any) through which this request was
1182 received. This should B<only> be used to access underlying state
1183 information about the Socket, such as the SSL information of a
1184 B<IO::Socket::SSL>.
1185  
1186 =cut
1187  
1188 sub getSocket {
1189 my $self = shift;
1190  
1191 return $self->{socket};
1192 }
1193  
1194 =pod
1195  
1196 =item setSocket($socket)
1197  
1198 Set the Socket (if any) through which this request was received.
1199  
1200 B<Parameters:>
1201  
1202 =over
1203  
1204 =item $socket
1205  
1206 the B<IO::Socket> through which this request was received
1207  
1208 =back
1209  
1210 =cut
1211  
1212 sub setSocket {
1213 my $self = shift;
1214 my $socket = shift;
1215  
1216 $self->{socket} = $socket;
1217 }
1218  
1219 =pod
1220  
1221 =item getWrapper()
1222  
1223 Return the Wrapper within which this request is being processed.
1224  
1225 =cut
1226  
1227 sub getWrapper {
1228 my $self = shift;
1229  
1230 return $self->{wrapper};
1231 }
1232  
1233 =pod
1234  
1235 =item setWrapper($wrapper)
1236  
1237 Set the Wrapper within which this request is being processed. This
1238 must be called as soon as the appropriate Wrapper is identified, and
1239 before the request is ultimately passed to an application servlet.
1240  
1241 B<Parameters:>
1242  
1243 =over
1244  
1245 =item $wrapper
1246  
1247 the B<Wombat::Wrapper> associated with this request
1248  
1249 =back
1250  
1251 =cut
1252  
1253 sub setWrapper {
1254 my $self = shift;
1255 my $wrapper = shift;
1256  
1257 $self->{wrapper} = $wrapper;
1258 }
1259  
1260 =pod
1261  
1262 =back
1263  
1264 =head1 PUBLIC METHODS
1265  
1266 =over
1267  
1268 =item createInputHandle()
1269  
1270 Create and return a B<Servlet::ServletInputHandle> to read the content
1271 associated with this request.
1272  
1273 B<Throws:>
1274  
1275 =over
1276  
1277 =item Servlet::Util::IOException
1278  
1279 if an input or output error occurs
1280  
1281 =back
1282  
1283 =cut
1284  
1285 sub createInputHandle {
1286 my $self = shift;
1287  
1288 return Wombat::Connector::RequestHandle->new($self);
1289 }
1290  
1291 =pod
1292  
1293 =item finishRequest()
1294  
1295 Perform whatever actions are required to flush and close the input
1296 handle or reader.
1297  
1298 B<Throws:>
1299  
1300 =over
1301  
1302 =item Servlet::Util::IOException
1303  
1304 if an input or output error occurs
1305  
1306 =back
1307  
1308 =cut
1309  
1310 sub finishRequest {
1311 my $self = shift;
1312  
1313 # Wombat::Globals::DEBUG &&
1314 # $self->debug("finishing request");
1315  
1316 if ($self->{reader}) {
1317 $self->{reader}->close();
1318 }
1319  
1320 if ($self->{input}) {
1321 $self->{input}->close();
1322 }
1323  
1324 # the underlying handle and socket are the connector's
1325 # responsibility
1326  
1327 return 1;
1328 }
1329  
1330 =pod
1331  
1332 =item recycle()
1333  
1334 Release all object references and initialize instances variables in
1335 preparation for use or reuse of this object.
1336  
1337 =cut
1338  
1339 sub recycle {
1340 my $self = shift;
1341 my $facade = shift;
1342  
1343 # Wombat::Request instance variables
1344 $self->{application} = undef;
1345 $self->{authorization} = undef;
1346 $self->{connector} = undef;
1347 $self->{facade} = $facade || Wombat::Connector::RequestFacade->new($self);
1348 $self->{handle} = undef; # the handle from which request data is read
1349 $self->{response} = undef;
1350 $self->{socket} = undef; # the actual request socket, if any
1351 $self->{wrapper} = undef;
1352  
1353 # Servlet::ServletRequest instance variables
1354 $self->{attributes} = {};
1355 $self->{characterEncoding} = undef;
1356 $self->{contentLength} = undef;
1357 $self->{contentType} = undef;
1358 $self->{defaultLocale} = 'en_US'; # XXX
1359 $self->{input} = undef; # the Servlet::ServletInputHandle wrapper
1360 $self->{locales} = [];
1361 $self->{parameters} = {};
1362 $self->{protocol} = {};
1363 $self->{reader} = undef; # character handle
1364 $self->{remoteAddr} = undef;
1365 $self->{remoteHost} = undef;
1366 $self->{scheme} = undef;
1367 $self->{serverName} = undef;
1368 $self->{serverPort} = undef;
1369 $self->{secure} = undef;
1370  
1371 return 1;
1372 }
1373  
1374 =pod
1375  
1376 =back
1377  
1378 =cut
1379  
1380 # private methods
1381  
1382 sub log {
1383 my $self = shift;
1384  
1385 $self->{connector}->log(@_) if $self->{connector};
1386  
1387 return 1;
1388 }
1389  
1390 sub debug {
1391 my $self = shift;
1392  
1393 # extra check in case we forget to check DEBUG before
1394 $self->log($_[0], undef, 'DEBUG') if Wombat::Globals::DEBUG;
1395  
1396 return 1;
1397 }
1398  
1399 1;
1400 __END__