Moose :: Manual :: Attributes states:
As an alternative to using the routine reference [default], you can instead create a build method for your attribute: ... This has several advantages. First, it moves a piece of code into its own named method, which improves the readability and organization of the code.
So your attribute can define a default value:
has attr => ( is => 'ro', builder => 'subroutine' ); sub subroutine { # figure out and return default value }
I do not understand why this should be separate from default. Could you just pass the link to the named routine?
has attr => ( is => 'ro', default => \&subroutine );
And would it not be a more complicated programming practice, since you should not accidentally refer to a routine that does not exist? You are referring to a method with a logical link instead of a symbolic link.
perl moose
skiphoppy
source share