DBIx::...ypeEnum(3pm)

πŸ’– DBIx::Class::InflateColumn::ClassTypeEnum β€” the vibe check πŸ’–

okay so bestie, you know those Perl manual pages that read like a robot explaining taxes? yeah. this one is from the User Contributed Perl Documentation, which is basically the group chat of Perl docs, and honestly? it's serving.


✨ NAME ✨

DBIx::Class::InflateColumn::ClassTypeEnum β€” inflate enum-like columns into your Class::Type::Enum classes. no cap, that's the whole job and it does it beautifully. πŸ’…

🌸 VERSION 🌸

version 0.014 β€” she's got a version number and she's proud of it. ✨

πŸŽ€ SYNOPSIS πŸŽ€

here's the moment you've all been waiting for, the copy-paste-able glow-up:

package My::Schema::Result::Toast {
  __PACKAGE__->load_components(qw/ InflateColumn::ClassTypeEnum Core /);

  # Assuming Toast::Status is one of your enum classes...

  use Toast::Status;  # Ensure it is loaded.

  __PACKAGE__->add_columns(
    status => {
      data_type => 'varchar',
      extra     => {
        enum_class => 'Toast::Status',
      },
    }
  );
}

yes bestie, your schema result package is literally called Toast. iconic behavior. 🍞

πŸ’œ DESCRIPTION πŸ’œ

so what's actually happening here: this component takes your DBIC columns and inflates them into instances of your Class::Type::Enum classes. that's it, that's the flex. πŸ”₯

and here's the tea β€” the storage data_type does not matter here. literally doesn't care. the only thing that matters is whether your enums should inflate/deflate to symbols (aka strings) or to ordinals (aka integers). pick your fighter. 🌈

πŸ‘‘ METHODS πŸ‘‘

πŸ¦‹ register_column($column, $info)

this method chains with "register_column" in DBIx::Class::Row, and it goes digging around inside the extra key of the column info looking for two little subkeys. two. exactly two. it's very specific about this. πŸ”

  • enum_class β€” this one is Required to enable column inflation, so like, no skipping it bestie. you put in the complete class name that this column should be inflated to. and heads up: it should already be loaded, and it must be a subclass of Class::Type::Enum. the vibes must be correct. πŸ’–
  • enum_ordinal_storage β€” if this is true, then the column gets inflated from and deflated to ordinal values. simple as that, periodt. ✨

⭐ SEE ALSO ⭐

  • Class::Type::Enum β€” the main character this whole module is obsessed with πŸ’œ
  • DBIx::Class::InflateColumn::Object::Enum β€” the other one, also valid, also serving 🫢

🧚 AUTHOR 🧚

Meredith Howard <mhoward@cpan.org> β€” absolute legend, give her flowers πŸ’

This software is copyright (c) 2018 by Meredith Howard.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. fr fr, free as in freedom, go wild. πŸ•ŠοΈ


and that's the whole page bestie!! πŸŽ€ this little number shipped as perl v5.32.1 on 2021-08-02, and she's still cute. mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from