Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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
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
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 musing on the Monastery: (13)
As of 2015-07-31 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls