Wombat/Core/Host.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 121 CC 8 SCAR 16.2
CC
8
Cov
0%
removeAlias
12.0
setAppBase
6.0
setName
6.0
CRAP 5.0
1 # -*- Mode: Perl; indent-tabs-mode: nil; -*-
2  
3 package Wombat::Core::Host;
4  
5 use base qw(Wombat::Core::ContainerBase);
6 use fields qw(aliases appBase);
7 use strict;
8 use warnings;
9  
10 use File::Spec ();
11 use Servlet::Util::Exception ();
12 use Wombat::Core::HostValve ();
13  
14 sub new {
15 my $class = shift;
16  
17 my $self = fields::new($class);
18 $self->SUPER::new();
19  
20 $self->{aliases} = [];
21 $self->{appBase} = undef;
22  
23 $self->{mapperClass} = 'Wombat::Core::HostMapper';
24 $self->{pipeline}->setBasic(Wombat::Core::HostValve->new());
25  
26 return $self;
27 }
28  
29 # accessors
30  
31 sub getAppBase {
32 my $self = shift;
33  
34 return $self->{appBase};
35 }
36  
37 sub setAppBase {
38 my $self = shift;
39 my $appBase = shift;
40  
41 $appBase = File::Spec->rel2abs($appBase, $ENV{WOMBAT_HOME}) unless
42 File::Spec->file_name_is_absolute($appBase);
43  
44 $self->{appBase} = $appBase;
45  
46 return 1;
47 }
48  
49 sub setName {
50 my $self = shift;
51 my $name = shift;
52  
53 unless ($name) {
54 my $msg = "setName: null host name not allowed";
55 Servlet::Util::IllegalArgumentException->throw($msg);
56 }
57  
58 $self->{name} = lc $name;
59  
60 return 1;
61 }
62  
63 # public methods
64  
65 sub addAlias {
66 my $self = shift;
67 my $alias = shift;
68  
69 for my $a (@{ $self->{aliases} }) {
70 return 1 if $alias eq $a;
71 }
72  
73 push @{ $self->{aliases} }, $alias;
74  
75 return 1;
76 }
77  
78 sub addChild {
79 my $self = shift;
80 my $child = shift;
81  
82 unless ($child->isa('Wombat::Core::Application')) {
83 my $msg = "addChild: child container must be Application";
84 Servlet::Util::IllegalArgumentException->throw($msg);
85 }
86  
87 $self->SUPER::addChild($child);
88  
89 return 1;
90 }
91  
92 sub getAliases {
93 my $self = shift;
94  
95 return @{ $self->{aliases} };
96 }
97  
98 sub removeAlias {
99 my $self = shift;
100 my $alias = shift;
101  
102 my $j = 0;
103 for (my $i=0; $i < @{ $self->{aliass} }; $i++) {
104 if ($alias eq $self->{aliass}->[$i]) {
105 $j = $i;
106 last;
107 }
108 }
109  
110 return 1 unless $j;
111  
112 splice @{ $self->{aliass} }, $j, 1;
113  
114 return 1;
115 }
116  
117 sub toString {
118 my $self = shift;
119  
120 my $parent = $self->getParent();
121 my $str = sprintf "Host[%s]", $self->getName();
122 $str = sprintf "%s.%s", $parent->toString(), $str if $parent;
123  
124 return $str;
125 }
126  
127 1;
128 __END__