Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 ( #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


Comment on Re: Of moose and ducks (or: how to coerce from non-Moose type objects)
Select or Download Code
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
Node Status?
node history
Node Type: note [id://881184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-07-14 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls