XP is just a number | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Fellow monks, I'm trying to refactor some legacy code using a Moose'ish way. The old code has tons of codepaths to work with different types of data (objects may be strings, hashrefs, regexps, arrayrefs) and I thought using Moose unions would probably be the way to go. Coercions are probably not the way to go, at least not in the general case, (the code may use coercions when e.g. 'consolidating' data structures). In order to get a little bit more structure to the whole thing, I thought of an abstraction into two Moose classes: 'KeyAtom' and 'ValAtom', where KeyAtom may be of type 'Str | RegexpRef' and ValAtom of the types that are valid for KeyAtom plus 'HashRef | ArrayRef'. Unfortunately, doing (shortened)Doesn't work. Of course, because KeyAtom naturally isn't the same as 'Str | RegexpRef'. So when the definition of ValAtom data type would have been. All works. However, true happiness doesn't come up, as this requires to manually maintain basically redundant information. So the core question is how to get the type definition in the inherited classes "do what I mean"? Bye In reply to Moose "unions" and inheritance by PetaMem
|
|