package Schema; sub new { my $pkg = shift; my $matrix = shift; my $self = {'patches' => [], 'components' => []}; my $size = @$matrix; for (my $i=0; $i<$size; $i++) { push(@{$self->{'components'}},$matrix->[$i][$size]); } for ($i=0; $i<$size; $i++) { for (my $j=0; $j<$size; $j++) { my $turn = $matrix->[$i][$j]; $self->{'patches'}[$turn]=new Patch($self->{'components'}[$j],$self->{'components'}[$i]) if ($turn); } } shift(@{$self->{'patches'}}); $self->{'in'} = $self->{'components'}[0]; $self->{'out'} = $self->{'components'}[$size-1]; bless $self,$pkg; return $self; } sub in { my $self = shift; $self->{'in'}->in(shift); } sub out { my $self = shift; return($self->{'out'}->out()); } sub pulse { my $self = shift; foreach my $kind ($self->{'patches'},$self->{'components'}) { foreach my $elt (@$kind) { $elt->pulse(); } } } 'end Schema';