On 04/13/2010 01:08 PM, Jesse Luehrs wrote:
On Tue, Apr 13, 2010 at 01:05:48PM -0400, Sir Robert Burbridge wrote:
Hey,
I've read through the MooseX::Types docs many times, but I can't quite
seem to get this to work. I've never worked with MooseX::Types before.
Could someone show me what I'm missing?
I'm trying to extend MooseX::Types::Set::Object to add two methods
(search and find) to allow getting subsets (or objects) based on search
criteria. Here's what I have so far, and it doesn't work. I don't
really have any broken code to put in here in place of the "???"
(because broken implies something even close to working). I tried a
bunch of stuff with "extends", "duck_type", "coerce", and "subtype",
before realizing I was just sort of flailing around =) I *think* I'm
supposed to be using some kind of role (to apply methods only?) but I
don't understand the manual or cookbook at all in this area.
The desired functionality:
- define a set of objects as a moose object property.
- use my $results = $obj->set->search(...criteria...) to find a proper
subset.
- use my $obj = $obj->set->find(...criteria...) to find the first
matching object (or undef)
If I get it working, I'm happy to submit a doc patch =)
Thanks,
-Sir
You're confusing classes and types. You want to do something like this:
package My::Set::Object;
use Moose;
extends 'Set::Object';
sub search { ... }
sub find { ... }
package My::Types;
use MooseX::Types -declare => ['MySetObject'];
class_type MySetObject, { class => 'My::Set::Object' };
Basically, the functionality needs to go in an actual subclass of
Set::Object, and then you need to create a type for that subclass.
-doy
Ahh, thanks. So typing is basically nomination of classes into a
program's cosmology. That's super helpful.
Thanks again,
-Sir