A simple example of a class using the construct_instance method.
construct_instance
Two roles hook onto it. One of them auto-loads classes at run time:
before construct_instance => sub { my ($self, $class) = @_; Module::Runtime::use_package_optimistically($class); };
The other uses an around modifier to tweak the constructed instance:
around
around construct_instance => sub { my $orig = shift; my $self = shift; my $inst = $self->$orig(@_); ...; return $inst; };
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooseX::ConstructInstance, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::ConstructInstance
CPAN shell
perl -MCPAN -e shell install MooseX::ConstructInstance
For more information on module installation, please visit the detailed CPAN module installation guide.