ASP/Config.pm

filter: Statementstmt 34.0% 16 / 47 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 3 totaltotal 31.8% 21 / 66 CC 8 SCAR 19.9
CC
8
Cov
30%
new
12.0
load_class
12.0
init_server_root
10.8
CRAP 7.3
« ASP/ConfigNode.pm ↑ Summary ASP/HTTPContext/FilterResolver.pm »
1  
2 package Apache2::ASP::Config;
3  
4 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use base 'Apache2::ASP::ConfigNode';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 #==============================================================================
11 sub new
12 {
13 0 ▶ my ($class, $ref, $root) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
14
15 0 my $s = $class->SUPER::new( $ref );
16
17 0 $s->init_server_root( $root );
18
19 0 $s->_init_inc();
20
21 0 foreach my $var ( $s->system->env_vars )
22 {
23 0 ▶ while( my ($key,$val) = each(%$var) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$var) 0 0 0
24 {
25 0 $ENV{$key} = $val;
26 }# end while()
27 }# end foreach()
28
29 0 map { $s->load_class( $_ ) } $s->system->load_modules;
30
31 0 return $s;
32 }# end new()
33  
34  
35 #==============================================================================
36 sub _init_inc
37 {
38 0 ▶ my $s = shift;
Subroutine _init_inc: not called CC=1 SCAR=6.9
39
40 0 my %saw = map { $_ => 1 } @INC;
41 0 push @INC, grep { ! $saw{$_}++ } ( $s->system->libs, $s->web->handler_root );
42 }# end _init_inc()
43  
44  
45 #==============================================================================
46 sub init_server_root
47 {
48 0 ▶ my ($s, $root) = @_;
Subroutine init_server_root: not called CC=4 SCAR=23.7
Pod undocumented
49
50 24 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
51 0 foreach( @{ $s->{system}->{libs}->{lib} } )
52 {
53 0 $_ =~ s/\@ServerRoot\@/$root/;
54 }# end foreach()
55
56 0 foreach( @{ $s->{system}->{settings}->{setting} } )
57 {
58 0 $_->{value} =~ s/\@ServerRoot\@/$root/;
59 }# end foreach()
60
61 0 foreach my $key (qw/ application handler media_manager_upload www page_cache /)
62 {
63 0 $s->{web}->{"$key\_root"} =~ s/\@ServerRoot\@/$root/;
64 }# end foreach()
65 }# end init_server_root()
66  
67  
68 #==============================================================================
69 sub load_class
70 {
71 0 ▶ my ($s, $class) = @_;
Subroutine load_class: not called CC=3 SCAR=24.8
Pod undocumented
72
73 0 (my $file = "$class.pm") =~ s/::/\//g;
74 0 ▶ eval { require $file unless $INC{$file}; 1 }
Branch: 2 branches
BranchTrueFalseTotal
eval { do { require $file unless $INC{$file}; 1 } } or confess("Cannot load ${class}: $@") 0 0 0
unless $INC{$file} 0 0 0
75 or confess "Cannot load $class: $@";
76 }# end load_class()
77  
78  
79 sub DESTROY
80 {
81 0 ▶ my $s = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
82 0 undef(%$s);
83 }
84  
85  
86 24 1;# return true:
87  
88 =pod
89  
90 =head1 NAME
91  
92 Apache2::ASP::Config - Central configuration for Apache2::ASP
93  
94 =head1 SYNOPSIS
95  
96 # Settings:
97 $Config->system->settings->some_setting;
98 $Config->system->settings->another_setting;
99
100 # Error-handling:
101 $Config->errors->error_handler;
102 $Config->errors->mail_errors_to;
103 $Config->errors->mail_errors_from;
104 $Config->errors->smtp_server;
105
106 # Web:
107 $Config->web->application_name;
108 $Config->web->application_root;
109 $Config->web->www_root;
110 $Config->web->handler_root;
111 $Config->web->media_manager_upload_root;
112 $Config->web->page_cache_root;
113
114 # Data Connections:
115 foreach my $conn ( map { $Config->data_connections->$_ } qw/ session application main / )
116 {
117 my $dbh = DBI->connect(
118 $conn->dsn,
119 $conn->username,
120 $conn->password
121 );
122 }# end foreach()
123  
124 =head1 XML Config File
125  
126 Apache2::ASP keeps all of its configuration inside of C</conf/apache2-asp-conf.xml>
127  
128 Here is an example:
129  
130 <?xml version="1.0" ?>
131 <configuration>
132  
133 <system>
134 <post_processors>
135 <!--
136 <class>My::PostProcessor</class>
137 <class>My::PostProcessor2</class>
138 -->
139 </post_processors>
140 <libs>
141 <lib>@ServerRoot@/lib</lib>
142 </libs>
143
144 <load_modules>
145 <module>DBI</module>
146 </load_modules>
147
148 <env_vars>
149 <var>
150 <name>myvar</name>
151 <value>value</value>
152 </var>
153 <var>
154 <name>myvar2</name>
155 <value>value2</value>
156 </var>
157 </env_vars>
158
159 <settings>
160 <setting>
161 <name>mysetting</name>
162 <value>value</value>
163 </setting>
164 <setting>
165 <name>mysetting2</name>
166 <value>value2</value>
167 </setting>
168 </settings>
169 </system>
170
171 <errors>
172 <error_handler>My::ErrorHandler</error_handler>
173 <mail_errors_to>jdrago_999@yahoo.com</mail_errors_to>
174
175 <mail_errors_from>root@localhost</mail_errors_from>
176 <smtp_server>localhost</smtp_server>
177 </errors>
178
179 <web>
180 <application_name>DefaultApp</application_name>
181 <application_root>@ServerRoot@</application_root>
182 <handler_root>@ServerRoot@/handlers</handler_root>
183 <media_manager_upload_root>@ServerRoot@/MEDIA</media_manager_upload_root>
184 <www_root>@ServerRoot@/htdocs</www_root>
185 <page_cache_root>@ServerRoot@/PAGE_CACHE</page_cache_root>
186 <request_filters>
187 <!--
188 <filter>
189 <uri_match>/.*</uri_match>
190 <class>My::MemberFilter</class>
191 </filter>
192 <filter>
193 <uri_equals>/index.asp</uri_equals>
194 <class>My::MemberFilter2</class>
195 </filter>
196 -->
197 </request_filters>
198
199 </web>
200
201 <data_connections>
202 <session>
203 <manager>Apache2::ASP::SessionStateManager::SQLite</manager>
204 <cookie_name>session-id</cookie_name>
205 <dsn>DBI:SQLite:dbname=/tmp/apache2_asp_applications</dsn>
206 <username></username>
207 <password></password>
208 <session_timeout>30</session_timeout>
209 </session>
210 <application>
211 <manager>Apache2::ASP::ApplicationStateManager::SQLite</manager>
212 <dsn>DBI:SQLite:dbname=/tmp/apache2_asp_applications</dsn>
213 <username></username>
214 <password></password>
215 </application>
216 <main>
217 <dsn>DBI:SQLite:dbname=/tmp/apache2_asp_applications</dsn>
218 <username></username>
219 <password></password>
220 </main>
221
222 </data_connections>
223
224 </configuration>
225  
226 =head1 DESCRIPTION
227  
228 =head1 PUBLIC PROPERTIES
229  
230 =head1 PUBLIC METHODS
231
232 =head1 BUGS
233
234 It's possible that some bugs have found their way into this release.
235
236 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
237
238 =head1 HOMEPAGE
239
240 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
241 of Apache2::ASP in action.
242  
243 =head1 AUTHOR
244  
245 John Drago <jdrago_999@yahoo.com>
246  
247 =head1 COPYRIGHT
248  
249 Copyright 2008 John Drago. All rights reserved.
250  
251 =head1 LICENSE
252  
253 This software is Free software and is licensed under the same terms as perl itself.
254  
255 =cut
256  
« ASP/ConfigNode.pm ↑ Summary ASP/HTTPContext/FilterResolver.pm »