How do I declare a class attribute as a union of class names?

前端 未结 3 1930
别那么骄傲
别那么骄傲 2021-01-12 08:41

I\'m reading a spreadsheet looking for different structures. When I tried the following using Moose it seems to do what I want. I could create different types of objects, as

3条回答
  •  天命终不由人
    2021-01-12 08:57

    You probably want them to do a common role and specify that as the type

    role Common {}
    class Sch-Symbol does Common {…}
    …
    
    class Cell {
      …
      has Common $.found is rw;
    }
    

    Or you will have to use a where constraint

    class Cell {
      …
      has $.found is rw where Sch-Symbol|Chip-Symbol|Net;
    }
    

    You could also create a subset to wrap the where constraint.

    subset Common of Any where Sch-Symbol|Chip-Symbol|Net;
    
    class Cell {
      …
      has Common $.found is rw;
    }
    

    Note that a where constraint is slower than using a common role.

提交回复
热议问题