MooseX :: Types of coercion and $ self

Is there any way to get $selfforced MooseX::Types? I have other data in the object that I want to use to align my compulsion from Stringto Object. Alternatively, there is something like Class::MOP initializerthat would allow me to do this - it should have worked before type checking.

The requested pseudo code:

with 'DBHandle';
has 'database' => ( isa => 'Str', is => 'ro', default => 'Db' );
has 'schema' => ( isa => 'Str', is => 'ro', default => 'schema' );
has 'table' => ( isa => 'Str', is => 'ro', default => 'column );

has 'columns' => ( isa => DBCols, is => 'ro', default => sub {[qw/foo bar baz/]} );

Here I want the "columns" to force DBCols- ArrayRef from DBCol (objects) - requiring the use of attributes catalog, schemaboth colfound in the class, and with dbh / singleton provided DBHandle.

To make this less pseudo, the situation is actually a bit more complicated. I was able to accomplish the above with around, now what I want to do is create an attribute tag that would allow this syntax to be used:

has 'column_id' => (
  isa => Int
  , is => 'ro'
  , traits => ['DBKey']
  , default => 5
  , column => 'foo'
);

If the attribute is columnprovided DBKey, koertsiruet to DBColthe same as the previous one columns: it would require access to the classes database, schema, tableand again for Singleton dbh.

+3
source share
1 answer

. , , , "- ", , . ( , s/coercions/type/- , , columns HashRef ".)

around / BUILD BUILDARGS.

+5

Source: https://habr.com/ru/post/1780915/


All Articles