# Visitor Pattern in Perl, using package/bless appraoch to oop # we're going to implement visitees as linked list cells package visitee; sub newvisitee { my $t = $_[0]; my $hash = { "tail" => $t }; bless $hash, visitee; } sub accept { my ($this,$visitor1) = @_; visitor->visit($visitor1,$this); } package singleton; @ISA = ("visitee"); sub newsingle { my ($x,$t) = @_; my $hash = visitee->newvisitee($t); $hash->{"head"} = $x; bless $hash, "singleton"; } package couple; @ISA = ("visitee"); sub newcouple { my ($x,$y,$t) = @_; my $hash = visitee->newvisitee($t); $hash->{"left"} = $x; $hash->{"right"} = $y; bless $hash, "couple"; } package