Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Of moose and ducks (or: how to coerce from non-Moose type objects)

by stvn (Monsignor)
on Jan 08, 2011 at 00:59 UTC ( [id://881184]=note: print w/replies, xml ) Need Help??


in reply to Of moose and ducks (or: how to coerce from non-Moose type objects)

You could have also done this ...

class_type('Bio::Seq'); coerce 'DNAString' => from 'Bio::Seq' => via { $_->seq };
Moose class types are not restricted to Moose created classes, you can make one for any plain old Perl class. Of course the version you have is more flexible, assuming you know you can trust the seq method.

-stvn

Replies are listed 'Best First'.
Re^2: Of moose and ducks (or: how to coerce from non-Moose type objects)
by tospo (Hermit) on Jan 10, 2011 at 10:51 UTC
    Ah, ok - I didn't know the class_type construct. That's a useful one. But in this case, I think my version is more suitable because there are many BioPerl classes that implement a 'seq' method, so ducktyping is indeed more flexible.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://881184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found