The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MOP4Import::Base::Configure - OO Base class (based on MOP4Import)

SYNOPSIS

  package MyPSGIMiddlewareSample {
    use MOP4Import::Base::Configure -as_base
      , [fields =>

         , [app =>
             , doc => 'For Plack::Middleware standard conformance.']

         , [dbname =>
             , doc => 'Name of SQLite dbfile']
        ];

    use parent qw( Plack::Middleware );

    use DBI;

    sub call {
      (my MY $self, my $env) = @_;

      $env->{'myapp.dbh'} = DBI->connect("dbi:SQLite:dbname=$self->{dbname}");

      return $self->app->($env);
    }
  };

DESCRIPTION

MOP4Import::Base::Configure is a MOP4Import family and is my latest implementation of Tk-like configure based object base classs. This class also inherits MOP4Import::Declare, so you can define your own declare_.. pragmas too.

METHODS

new (%opts | \%opts)

Usual constructor. This passes given %opts to "configure".

configure (%opts | \%opts)

General setter interface for public fields. See also Tk style configure method.

configure_default ()

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.

HOOK METHODS

after_new

This hook is called just after call of configure in new.

FIELD SPECs

For field spec, you can also have hook for field spec.

default => VALUE

This defines default_FIELDNAME method with given VALUE.

weakref => 1

This generates set hook (onconfigure_FIELDNAME) wrapped with "weaken" in Scalar::Util.