Wombat/Core/EngineMapper.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 77 CC 8 SCAR 33.9
CC
8
Cov
0%
map
56.0
setContainer
6.0
BEGIN
2.0
CRAP 29.6
1 # -*- Mode: Perl; indent-tabs-mode: nil; -*-
2  
3 package Wombat::Core::EngineMapper;
4  
5 =pod
6  
7 =head1 NAME
8  
9 Wombat::Core::EngineMapper - internal mapper base class
10  
11 =head1 SYNOPSIS
12  
13 =head1 DESCRIPTION
14  
15 Implementation of B<Wombat::Mapper> for a B<Wombat::Core::Engine>.
16  
17 =cut
18  
19 use base qw(Wombat::Core::MapperBase);
20 use strict;
21 use warnings;
22  
23 use Servlet::Util::Exception ();
24  
25 =pod
26  
27 =head1 ACCESSOR METHODS
28  
29 =over
30  
31 =item setContainer($container)
32  
33 Set the Container with which the Mapper is associated.
34  
35 B<Parameters:>
36  
37 =over
38  
39 =item $container
40  
41 the B<Wombat::Container> used for processing Requests
42  
43 =back
44  
45 B<Throws:>
46  
47 =over
48  
49 =item B<Servlet::Util::IllegalArgumentException>
50  
51 if the Container is not acceptable to this Mapper
52  
53 =back
54  
55 =cut
56  
57 sub setContainer {
58 my $self = shift;
59 my $container = shift;
60  
61 unless ($container && $container->isa('Wombat::Core::Engine')) {
62 my $msg = "setContainer: container is not Engine\n";
63 Servlet::Util::IllegalArgumentException->throw($container);
64 }
65  
66 $self->SUPER::setContainer($container);
67  
68 return 1;
69 }
70  
71 =pod
72  
73 =back
74  
75 =head1 PUBLIC METHODS
76  
77 =over
78  
79 =item map($request)
80  
81 Return the child Container that should be used to process the
82 Request, or C<undef> f no such child Container can be identified.
83  
84 B<Parameters:>
85  
86 =over
87  
88 =item $request
89  
90 the B<Wombat::Request> being processed
91  
92 =back
93  
94 =cut
95  
96 sub map {
97 my $self = shift;
98 my $request = shift;
99  
100 my $engine = $self->getContainer();
101 my $freq = $request->getRequest();
102  
103 # figure out the requested server name
104 my $server = $freq->getServerName();
105 unless ($server) {
106 $server = $engine->getDefaultHost();
107 $freq->setServerName($server);
108 }
109  
110 return undef unless $server;
111 $server = lc $server;
112  
113 # try direct match
114 my $host = $engine->getChild($server);
115  
116 unless ($host) {
117 # try aliases
118 no warnings; # shut up "* matches null string many times"
119 for my $child ($engine->getChildren()) {
120 for my $alias ($child->getAliases()) {
121 if ($server =~ /^$alias$/) {
122 $host = $child;
123 last;
124 }
125 }
126 last if $host;
127 }
128 }
129  
130 unless ($host) {
131 # try default host
132 $host ||= $engine->getChild($engine->getDefaultHost());
133 }
134  
135 return $host;
136 }
137  
138 1;
139 __END__