I use Moose objects, but I need to declare static members for things that will only execute once and are not associated with the object.
Do you have any ideas or examples?
thank
Dotan.
You can use MooseX :: ClassAttribute :
package SomeClass; use Moose; use MooseX::ClassAttribute; class_has 'static_member' => ( is => 'rw' );
An item is accessed using SomeClass->static_member.
SomeClass->static_member
I tried playing with MooseX :: ClassAttribute as a bvr suggestion, but in the end I just set them as read-only members with a default value:
has 'static_thing' => ( is => 'ro', init_arg => undef, default => 42 );
It seems easier.
Perl
.pm file
package SomeClass; use Moose; my $instance_counter = 0; around BUILDARGS => sub { $instance_counter += 1; } . . .