File: README.md

package info (click to toggle)
libclass-type-enum-perl 0.014-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 136 kB
  • sloc: perl: 178; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Class::Type::Enum

Class::Type::Enum is a class builder for type-like enumeration classes.

It's a bit of an experiment that grew from liking [Object::Enum][objenum] and
using it with [DBIC][dbic], but prefering something more akin to defining
types, with traditional numeric backing values and sortability.  Object::Enum
instances are all just instances of Object::Enum. I'd love to hear thoughts or
advice.

[Object::Enum][objenum] works nicely for varchars with enum-like sets of
values, but all enums you get out of it are instances of Object::Enum.
Instead, this is a class builder which lets you treat that class as an enum
type.

Thanks to the ordinal values behind these enums, they can be sorted either by
ordinal (`<=>`) or by symbol (`cmp`).  This also allows for checks like
`$thing->status > $approved` in addition to the usual `$thing->status->is_foo`
checks.  There is no check that you're comparing similar types, as comparison
is just happening through overload fallback after stringify and numify.

_Unlike_ Object::Enum, objects are not mutable.  I may add methods that return
new instances though, for example `next` and `prev`...

Also I liked `is_any` and `is_none` from [Enumeration][enumeration] and added
the same, as `any` and `none`.

## License

This software is licensed under the same terms as the Perl distribution itself.

[dbic]: https://metacpan.org/pod/DBIx::Class
[objenum]: https://metacpan.org/pod/Object::Enum
[enumeration]: https://metacpan.org/pod/Enumeration