Many radical changes to the IRSpy engine, enabling a far more asynchronous approach...
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Node.pm
1 # $Id: Node.pm,v 1.1 2006-10-06 11:33:07 mike Exp $
2
3 package ZOOM::IRSpy::Node;
4
5 use 5.008;
6 use strict;
7 use warnings;
8
9
10 sub new {
11     my $class = shift();
12     my($name, @subtests) = @_;
13     return bless {
14         name => $name,
15         subtests => \@subtests,
16     }, $class;
17 }
18
19 sub name {
20     my $this = shift();
21     return $this->{name};
22 }
23
24 sub subtests {
25     my $this = shift();
26     return @{ $this->{subtests} };
27 }
28
29 sub print {
30     my $this = shift();
31     my($level) = @_;
32
33     print "\t" x $level, $this->name();
34     if (my @sub = $this->subtests()) {
35         print " = {\n";
36         foreach my $sub (@sub) {
37             $sub->print($level+1);
38         }
39         print "\t" x $level, "}";
40     }
41     print "\n";
42 }
43
44 # Addresses are of the form:
45 #       (empty) - the root
46 #       2 - subtree #2 (i.e. the third subtree) of the root
47 #       2:1 - subtree #1 of subtree #2, etc
48 sub select {
49     my $this = shift();
50     my($address) = @_;
51
52     my @sub = $this->subtests();
53     if ($address eq "") {
54         return $this;
55     } elsif (my($head, $tail) = $address =~ /(.*):(.*)/) {
56         return $sub[$head]->select($tail);
57     } else {
58         return $sub[$address];
59     }
60 }
61
62
63 1;