MOP4Import::Base::Configure - Base class with configure() interface for fields
package MyMetaCPAN { use MOP4Import::Base::Configure -as_base , [fields => [baseurl => default => 'https://fastapi.metacpan.org/v1'], ] ; sub get { (my MY $self, my $entry) = @_; $self->furl_get("$self->{baseurl}$entry"); } } # my $obj = MyMetaCPAN->new; print $obj->baseurl; # => https://fastapi.metacpan.org/v1 $obj->get("/author/someone"); $obj = MyMetaCPAN->new(baseurl => 'http://localhost:8000'); # $obj = MyMetaCPAN->new({baseurl => 'http://localhost:8000'}); # $obj->configure(baseurl => 'http://localhost:8000'); print $obj->baseurl; # => 'http://localhost:8000' $obj->get("/author/someone");
MOP4Import::Base::Configure is a minimalistic base class for fields based OO with support of Tk-like new/configure interface, automatic getter generation and default value initialization.
This class also inherits MOP4Import::Declare, so you can define your own declare_.. pragmas too.
declare_..
Usual constructor. This passes given %opts to "configure". Actual implementation is following:
%opts
sub new :method { my MY $self = fields::new(shift); $self->configure(@_); $self->before_configure_default; $self->after_new; # Note: deprecated. $self->configure_default; $self->after_configure_default; $self; }
General setter interface for public fields. See also Tk style configure method.
This fills undefined public fields with their default values. Default values are obtained via default_FIELD hook. They are normally defined by default field spec.
default_FIELD
This hook is called after configure and just before configure_default. This is useful to change behavior whether specific option is given or not.
This hook is called after configure_default. This is useful to compute all fields are filled with default values.
This method is called just before configure_default.
For field spec, you can also have hook for field spec.
This defines default_FIELDNAME method with given VALUE.
default_FIELDNAME
This generates set hook (onconfigure_FIELDNAME) wrapped with "weaken" in Scalar::Util.
To be documented...
MOP4Import::Declare
Kobayashi, Hiroaki <hkoba@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MOP4Import::Declare, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MOP4Import::Declare
CPAN shell
perl -MCPAN -e shell install MOP4Import::Declare
For more information on module installation, please visit the detailed CPAN module installation guide.