In similar to the sub { ... }
syntax it would be possible to do a $myclass = class { ... }
, construct and get a reusable class as a scalar. (=first order object). In Perl 5, namespaces are global and cannot be created on the fly without some namespace collision prevention Voodoo. In Rindolf, such classes can simply be assigned to variable. (bless
and similar operators will accept such classes as their second argument):
my $myclass = class { sub new { my $class = shift; my $self = {}; bless($self, $class); # $self->{'counter'} = 10; pt_return $self; } sub decrement { my $self = shift; sleep(1); my $val = --$self->{'counter'}; print "$val\n"; if ($val == 0) { die "Take off!"; } } }; my $countdown = $myclass->new(); for(;;) { $countdown->decrement(); }
This class references will also be accepted by @ISA and all other operators requiring class names.