Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 meditating upon the Monastery: (9)
As of 2014-12-27 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls