----- Original Message ----
> From: Evan Carroll <m...@evancarroll.com>
> To: "moose@perl.org ML" <moose@perl.org>
> Sent: Fri, December 17, 2010 3:00:06 PM
> Subject: MooseX::Types coercions and $self
>
> Copied from http://stackoverflow.com/q/4473327/124486
>
> The below is not as well formatted:
>
> Is there anyway to get $self into a MooseX::Types coercion? I have
> other data in the object that I want to use to seed my coercion from a
> String to an Object. Alternatively, is there anything like
> Class::MOP's initializer that will permit me to do this -- it would
> have to fire before the type checks.
>
> 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 "columns" to coerce to a DBCols -- an ArrayRef of DBCol's
> (objects) -- requiring the use of catalog, schema, and col attributes
> found in the class, and with a dbh/singleton provided by DBHandle.
>
> To make this less-pseudo, the actually situation is only slightly more
> complex. I was able to accomplish the above with around, now what I
> want I to do is create an attribute trait that would permit this
> syntax:
>
> has 'column_id' => (
> isa => Int
> , is => 'ro'
> , traits => ['DBKey']
> , default => 5
> , column => 'foo'
> );
> Where the attribute trait column provided by DBKey, coerces to DBCol
> the same way that the above columns would: this would require the
> ability to access the classes database, schema, table, and again the
> singleton for the dbh.
I actually published
http://search.cpan.org/perldoc?MooseX::Types::Parameterizable as an experiment
in starting to provide this capacity. I know someone did some work along these
ways over at http://search.cpan.org/perldoc?MooseX::Types::DBIx::Class building
on top of that. Last time I thought about this issue I also thought an
attribute trait might be the right way to go, but I put it aside a bit to see
what, if anything, was useful with MXT:Parameterizable. Mst told me this was
probably achievable using just MXT:Structured for what that's worth, although I
could just be mis-remembering
john
>
> --
> Evan Carroll - m...@evancarroll.com
> System Lord of the Internets
> web: http://www.evancarroll.com
> ph: 281.901.0011
>