in reply to oop, variable that counts the number of objects created
Just a random example using Zydeco...
use Zydeco prefix => 'App'; class Car { has name ( type => Str ); has price ( type => Num ); has speed ( type => Num, default => 0, handles_via => 'Number', handles => { speed_up => 'add', slow_down => 'sub', }, ); my $count; method BUILD { ++$count } method DEMOLISH { --$count } method count { $count } } my $red_car = App->new_car( name => 'Red' ); my $blue_car = App->new_car( name => 'Blue' ); $red_car->speed_up( 25 ); $red_car->speed_up( 10 ); say $red_car->speed; say App::Car->count;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: oop, variable that counts the number of objects created
by perlfan (Parson) on Jul 30, 2020 at 16:22 UTC | |
by tobyink (Canon) on Jul 30, 2020 at 17:01 UTC | |
by perlfan (Parson) on Jul 30, 2020 at 18:45 UTC | |
by chromatic (Archbishop) on Jul 30, 2020 at 22:08 UTC | |
by bliako (Abbot) on Jul 31, 2020 at 09:38 UTC | |
| |
by perlfan (Parson) on Jul 30, 2020 at 22:43 UTC | |
|