VBTK/Templates.pm untested

filter: Statementstmt 0.0% 0 / 81 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 147 CC 14 SCAR 41.6
CC
14
Cov
0%
new
156.0
getUpgradeRuleObjText
6.0
getChangeActionObjText
6.0
CRAP 64.1
1 #! /bin/perl
2 #############################################################################
3 #
4 # NOTE: This file under revision control using RCS
5 # Any changes made without RCS will be lost
6 #
7 # $Source: /usr/local/cvsroot/vbtk/VBTK/Templates.pm,v $
8 # $Revision: 1.5 $
9 # $Date: 2002/03/04 20:53:07 $
10 # $Author: bhenry $
11 # $Locker: $
12 # $State: Exp $
13 #
14 # Purpose: A common perl library to handle the definition of
15 # vbserver object templates.
16 #
17 # Description: This perl library contains methods to handle the
18 # definition of vbserver object templates. The
19 # templates are used to define object attributes
20 # such as actions related to status changes,
21 # descriptions of the objects, etc.
22 #
23 # Directions:
24 #
25 # Invoked by: vbserver
26 #
27 # Depends on: VBTK::Common.pm, Date::Manip.pm
28 #
29 # Copyright (C) 1996-2002 Brent Henry
30 #
31 # This program is free software; you can redistribute it and/or
32 # modify it under the terms of version 2 of the GNU General Public
33 # License as published by the Free Software Foundation available at:
34 # http://www.gnu.org/copyleft/gpl.html
35 #
36 # This program is distributed in the hope that it will be useful,
37 # but WITHOUT ANY WARRANTY; without even the implied warranty of
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 # GNU General Public License for more details.
40 #
41 #############################################################################
42 #
43 #
44 # REVISION HISTORY:
45 #
46 # $Log: Templates.pm,v $
47 # Revision 1.5 2002/03/04 20:53:07 bhenry
48 # *** empty log message ***
49 #
50 # Revision 1.4 2002/03/04 16:49:09 bhenry
51 # Changed requirement back to perl 5.6.0
52 #
53 # Revision 1.3 2002/03/02 00:53:55 bhenry
54 # Documentation updates
55 #
56 # Revision 1.2 2002/01/21 17:07:40 bhenry
57 # Disabled 'uninitialized' warnings
58 #
59 # Revision 1.1.1.1 2002/01/17 18:05:57 bhenry
60 # VBTK Project
61 #
62 #
63  
64 package VBTK::Templates;
65  
66 use 5.6.0;
67 use strict;
68 use warnings;
69 # I like using undef as a value so I'm turning off the uninitialized warnings
70 no warnings qw(uninitialized);
71  
72 use VBTK::Common;
73 use VBTK::Objects::UpgradeRules;
74 use VBTK::Objects::ChangeActions;
75 use Date::Manip;
76 use CGI qw(:html3 :standard);
77  
78 our $VERBOSE=$ENV{'VERBOSE'};
79  
80 #-------------------------------------------------------------------------------
81 # Function: new
82 # Description: Object constructor. Allocates memory for all class members
83 # Input Parms: Configuration filename
84 # Output Parms: Pointer to class
85 #-------------------------------------------------------------------------------
86 sub new
87 {
88 my $type = shift;
89 my $self = {};
90 bless $self, $type;
91  
92 # Store all passed input name pairs in the object
93 $self->set(@_);
94  
95 # Setup a hash of rules to be returned
96 my $defaultParms = {
97 Pattern => $::REQUIRED,
98 StatusHistoryLimit => undef,
99 StatusChangeActions => undef,
100 StatusUpgradeRules => undef,
101 ExpireAfter => undef,
102 Description => undef
103 };
104  
105 # Run the validation
106 $self->validateParms($defaultParms) || &fatal("Exiting");
107  
108 &log("Creating new object template '$self->{Pattern}'") if ($VERBOSE);
109  
110 my ($upgradeStr,$upgradeRuleObj,$status,$action,$changeActionObj,$test);
111  
112 # Check the upgrade rules
113 if(defined $self->{StatusUpgradeRules})
114 {
115 # If the upgrade rule is just a string, then make it an array
116 $self->{StatusUpgradeRules} = [ $self->{StatusUpgradeRules} ]
117 unless(ref($self->{StatusUpgradeRules}));
118  
119 # Step through each status upgrade rule
120 foreach $upgradeStr (@{$self->{StatusUpgradeRules}})
121 {
122 $upgradeRuleObj = new VBTK::Objects::UpgradeRules(
123 RuleText => $upgradeStr);
124  
125 &fatal("Exiting") if (! defined $upgradeRuleObj);
126  
127 push(@{$self->{upgradeRuleObjList}},$upgradeRuleObj);
128 }
129 }
130  
131 # Check the status change actions
132 if(defined $self->{StatusChangeActions})
133 {
134 &fatal("StatusChangeActions parm must be a hash")
135 unless (ref($self->{StatusChangeActions}) eq 'HASH');
136  
137 # Step through each status change action
138 while(($status,$action) = each %{$self->{StatusChangeActions}})
139 {
140 $changeActionObj = new VBTK::Objects::ChangeActions(
141 TestStatus => $status,
142 ActionList => $action);
143  
144 &fatal("Exiting") if (! defined $changeActionObj);
145  
146 $changeActionObj->validateActionNames || &fatal("Exiting");
147  
148 push(@{$self->{changeActionObjList}},$changeActionObj);
149 }
150 }
151  
152 # Check the 'ExpireAfter' key for a valid date string
153 if(defined $self->{ExpireAfter})
154 {
155 $test = &DateCalc("today",$self->{ExpireAfter});
156 &fatal("Invalid ExpireAfter string '$self->{ExpireAfter}' specified " .
157 "for template '$self->{Pattern}'") if ($test eq '');
158 }
159  
160 # Check the 'LimitHistoryTo' key for a valid date string
161 if((defined $self->{LimitHistoryTo})&&($self->{LimitHistoryTo} !~ /^\d+$/))
162 {
163 $test = &DateCalc("today",$self->{LimitHistoryTo});
164 &fatal("Invalid LimitHistoryTo string '$self->{LimitHistoryTo}' specified " .
165 "for template '$self->{Pattern}'") if ($test eq '');
166 }
167  
168 ($self);
169 }
170  
171 #-------------------------------------------------------------------------------
172 # Function: getUpgradeRuleObjText
173 # Description: Retrieve an array of text describing the upgrade rules
174 # Input Parms: None
175 # Output Parms: Array of text describing the upgrade rules for this object
176 #-------------------------------------------------------------------------------
177 sub getUpgradeRuleObjText
178 {
179 my $self = shift;
180 my $upgradeRuleObjList = $self->{upgradeRuleObjList};
181 return () if (! defined $upgradeRuleObjList);
182  
183 map { $_->getRuleText } @{$upgradeRuleObjList};
184 }
185  
186 #-------------------------------------------------------------------------------
187 # Function: getChangeActionObjText
188 # Description: Retrieve an array of text describing the change actions
189 # Input Parms: None
190 # Output Parms: Array of text describing the change actions for this object
191 #-------------------------------------------------------------------------------
192 sub getChangeActionObjText
193 {
194 my $self = shift;
195 my $changeActionObjList = $self->{changeActionObjList};
196 return () if (! defined $changeActionObjList);
197  
198 map { $_->getRuleText } @{$changeActionObjList};
199 }
200  
201 # Simple Get Methods
202 sub getDescription { $_[0]->{Description}; }
203 sub getPattern { $_[0]->{Pattern}; }
204 sub getExpireAfter { $_[0]->{ExpireAfter}; }
205 sub getUpgradeRuleObjList { $_[0]->{upgradeRuleObjList}; }
206 sub getChangeActionObjList { $_[0]->{changeActionObjList}; }
207  
208 1;
209 __END__