Revision: | 1.2 |
Committed: | Sat Oct 14 16:08:16 2000 UTC (24 years, 6 months ago) by williamc |
Content type: | text/plain |
Branch: | MAIN |
CVS Tags: | V0_19_7, V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2, V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1, V0_19_0, V0_18_5, V0_18_4, V_18_3_TEST, VO_18_3, V0_18_2, V0_18_1 |
Branch point for: | SCRAM_V1_BRANCH, V0_19_4_B, V0_16branch |
Changes since 1.1: | +21 -0 lines |
Log Message: | fully testted block |
# | Content |
---|---|
1 | # |
2 | # Block.pm |
3 | # |
4 | # Originally Written by Christopher Williams |
5 | # |
6 | # Description |
7 | # |
8 | # Interface |
9 | # --------- |
10 | # new(namestring) : A new Block object |
11 | # parent([Block]) : Set/get the parent - no parent = undef |
12 | # getobj(id) : get object associated with key - returns the nearest |
13 | # match going up the block tree |
14 | # setobj(oref,id) : hold an object reference with a key |
15 | # objectids() : return a list of all object ids |
16 | |
17 | |
18 | package BuildSystem::Block; |
19 | require 5.004; |
20 | |
21 | sub new { |
22 | my $class=shift; |
23 | my $self={}; |
24 | bless $self, $class; |
25 | $self->{objects}={}; |
26 | return $self; |
27 | } |
28 | |
29 | sub setobj { |
30 | my $self=shift; |
31 | my $oref=shift; |
32 | my $key=shift; |
33 | |
34 | $self->{objects}{$key}=$oref; |
35 | } |
36 | |
37 | sub getobj { |
38 | my $self=shift; |
39 | my $key=shift; |
40 | |
41 | my $oref=undef; |
42 | if ( ! exists $self->{objects}{$key} ) { |
43 | if ( defined $self->{parent} ) { |
44 | $oref=$self->{parent}->getobj($key); |
45 | } |
46 | } |
47 | else { |
48 | $oref=$self->{objects}{$key}; |
49 | } |
50 | return $oref; |
51 | } |
52 | |
53 | sub objectids { |
54 | my $self=shift; |
55 | |
56 | # -- get all local objs |
57 | my @objs=(keys %{$self->{objects}}); |
58 | |
59 | if ( defined $self->{parent} ) { |
60 | # -- add any objects from parent not found locally |
61 | foreach $obj ( $self->{parent}->objectids() ) { |
62 | my @tmp=grep ({ $_ eq $obj } @objs); |
63 | if ( $#tmp < 0 ) { |
64 | push @objs, $obj; |
65 | } |
66 | } |
67 | } |
68 | return @objs; |
69 | } |
70 | |
71 | sub parent { |
72 | my $self=shift; |
73 | if ( @_ ) { |
74 | $self->{parent}=shift; |
75 | } |
76 | return (defined $self->{parent})?$self->{parent}:undef; |
77 | } |