ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/GroupChecker.pm
Revision: 1.4
Committed: Tue Feb 27 13:33:03 2007 UTC (18 years, 2 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.3: +4 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 williamc 1.1 #
2     # Maintain a variable to indicate status of a number of requirements
3     #
4     # --------------
5     # Interface
6     #
7     # exclude(gp) : exclude a group
8     # unexclude(gp) : unexclude a group
9     # include(gp) : include a group
10     # uninclude(gp) : uninclude a group
11     # opencontext(gp) : Annonce group context
12 williamc 1.2 # closecontext(gp) : Close group context
13     # closelastcontext(set) : Close the last context added to group the group set
14 williamc 1.1 # status() : If include/excluded groups match the current gp context
15     # return 1 else 0
16     # getincluded() : return an array of included groups
17     # getexcluded() : return array of excluded groups
18 williamc 1.3 # clearinclude() : clear all entries from the include list
19     # clearexclude() : clear all entries from the exclude list
20 williamc 1.1 # ----------------------------------------------
21 williamc 1.2 # group names are characters. Anything before a :: will indicate the
22     # group set upon which the closecontext etc will operate. The group set is
23     # still part of the group name.
24     #
25 williamc 1.1
26 sashby 1.4
27 williamc 1.1 package GroupChecker;
28 sashby 1.4 BEGIN { print __PACKAGE__." still used.\n"; exit(1) }
29    
30    
31 williamc 1.1 require 5.001;
32     require Exporter;
33     @ISA=qw(Exporter);
34    
35     sub new {
36     my $class=shift;
37     $self={};
38     bless $self, $class;
39 williamc 1.2 $self->{context}{none}=1;
40 williamc 1.1 return $self;
41     }
42    
43 williamc 1.3 sub clearinclude {
44     my $self=shift;
45     undef %{$self->{include}};
46     }
47     sub clearexclude {
48     my $self=shift;
49     undef %{$self->{exclude}};
50     }
51    
52 williamc 1.1 sub exclude {
53     my $self=shift;
54     my $gp=shift;
55    
56     ${$self->{exclude}}{$gp}=1;
57     $self->_setstatus;
58     }
59    
60     sub unexclude {
61     my $self=shift;
62     my $gp=shift;
63    
64     delete ${$self->{exclude}}{$gp};
65     $self->_setstatus;
66     }
67    
68     sub include {
69     my $self=shift;
70     my $gp=shift;
71    
72     ${$self->{include}}{$gp}=1;
73     $self->_setstatus;
74     }
75    
76     sub uninclude {
77     my $self=shift;
78     my $gp=shift;
79    
80     delete ${$self->{include}}{$gp};
81     $self->_setstatus;
82     }
83    
84     sub getexcluded {
85     my $self=shift;
86     return keys %{$self->{exclude}}
87     }
88    
89     sub getincluded {
90     my $self=shift;
91     return keys %{$self->{include}}
92     }
93    
94     sub opencontext {
95     my $self=shift;
96     my $gp=shift;
97 williamc 1.3 my $set;
98 williamc 1.1
99 williamc 1.3 if ( $gp=~/(.*)::/ ) {
100     $set=$1;
101     }
102     else {
103     $set='none';
104     }
105 williamc 1.2
106     push @{$self->{contextstack}{$set}}, $gp;
107     $self->{context}{$gp}=1;
108     $self->_setstatus();
109 williamc 1.1 }
110    
111     sub closelastcontext {
112     my $self=shift;
113 williamc 1.2 my $set=shift;
114     my $gp;
115    
116     if ( $set eq "" ) { $set='none' }
117     do {
118     $gp=pop @{$self->{contextstack}{$set}};
119 williamc 1.3 } while ( (! exists $self->{context}{$gp}) && ($gp eq "") );
120 williamc 1.2 $self->closecontext($gp);
121     }
122 williamc 1.1
123 williamc 1.2 sub closecontext {
124     my $self=shift;
125     my $gp=shift;
126    
127 williamc 1.3 if ( $gp=~/(.*)::/ ) {
128     $set=$1;
129     }
130     else {
131     $set='none';
132     }
133 williamc 1.2 delete $self->{context}{$gp};
134     $self->_setstatus();
135 williamc 1.1 }
136    
137     sub status {
138     my $self=shift;
139     return $self->{status};
140     }
141    
142     # -------------- Support Routines -----------------------------------
143    
144     sub _setstatus {
145     my $self=shift;
146     my $i;
147    
148 williamc 1.3 $self->{status}=1;
149 williamc 1.2 foreach $i ( keys %{$self->{context}} ) {
150 williamc 1.1 if ( ( exists $self->{include}{$i} )
151     || ( exists $self->{include}{all} ) ) {
152 williamc 1.3 $self->{status}=( $self->{status} && 1);
153 williamc 1.1 }
154     if ( exists $self->{exclude}{$i} ) {
155     $self->{status}=0;
156     }
157     }
158     }