RWDE/Configuration.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 65 CC 3 SCAR 11.5
CC
3
Cov
0%
get_instance
6.0
FIELDNAME
6.0
initialize
2.0
CRAP 3.1
1 package RWDE::Configuration;
2  
3 use strict;
4  
5 use YAML qw(LoadFile);
6  
7 use RWDE::Configuration_content;
8  
9 use base qw(RWDE::Singleton);
10  
11 our $unique_instance;
12 our (@fieldnames, %fields, %static_fields, %modifiable_fields, @static_fieldnames, @modifiable_fieldnames);
13  
14 use vars qw($AUTOLOAD);
15 use vars qw($VERSION);
16 $VERSION = sprintf "%d", q$Revision: 507 $ =~ /(\d+)/;
17  
18 =pod
19  
20 =head1 RWDE::Configuration
21  
22 =cut
23  
24 =head2 get_instance()
25  
26 Get an instance of the Configuration sans content. You will need an initialized Configuration
27 in order to read the values in your project.conf file.
28  
29 #TODO Move this method to RWDE::Singleton
30  
31 =cut
32  
33 sub get_instance {
34 my ($self, $params) = @_;
35  
36 if (ref $unique_instance ne $self) {
37 $unique_instance = $self->new($params);
38 }
39  
40 return $unique_instance;
41 }
42  
43 =head2 initialize()
44  
45 Load the content from within the project configuration file via Configuration_content
46  
47 =cut
48  
49 sub initialize {
50 my ($self, $params) = @_;
51  
52 my $configuration_content = RWDE::Configuration_content->new($params);
53  
54 $self->{_configuration_content} = $configuration_content;
55  
56 return ();
57 }
58  
59 =head2 get_SMTP()
60  
61 Get an SMTP host - a random host is selected if the configuration specifies
62 a mail cluster
63  
64 =cut
65  
66 sub get_SMTP {
67 my ($self, $params) = @_;
68  
69 my $array_ref = $self->SMTPhost;
70  
71 return $$array_ref[ rand @{$array_ref} ];
72 }
73  
74 =head2 get_SMTP()
75  
76 Get a string representing the absolute path of the project
77  
78 =cut
79  
80 sub get_root {
81 my ($self, $params) = @_;
82  
83 return '/web/' . lc(RWDE::Configuration->ServiceName);
84 }
85  
86 =head2 AUTOLOAD()
87  
88 Catch configuration calls, so we can proxy them to the content provider
89  
90 =cut
91  
92 sub AUTOLOAD {
93 my ($self, @args) = @_;
94  
95 return $self->FIELDNAME($AUTOLOAD, @args);
96 }
97  
98 =head2 FIELDNAME()
99  
100 This is a wrapper function for Configuration content so that the calls can look like they are static
101 due to this object being a singleton, there's no multiple configuration loaded
102  
103 =cut
104  
105 sub FIELDNAME {
106 my $self = shift;
107 my $fn = shift;
108  
109 $fn =~ s/.*://; # strip fully-qualified portion
110  
111 my $instance = ref $self ? $self : $self->get_instance();
112 my $configuration_content = $instance->{_configuration_content};
113  
114 return $configuration_content->$fn;
115 }
116  
117 1;