DBIx::...Column(3pm)

πŸ“¦
version 0.00020 Β· 6 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’… NAME πŸ’…

ok so bestie, listen: DBIx::Class::EncodedColumn β€” it encodes your columns for you, automatically. that's the whole vibe. ✨

local manual page name: DBIx::...Column(3pm) (the header truncates it, but you know her).


πŸŽ€ SYNOPSIS πŸŽ€

so you're in your DBIx::Class Result class (which people sometimes ~erroneously~ call the 'table' class, iykyk):

  __PACKAGE__->load_components(qw/EncodedColumn ... Core/);

  #Digest encoder with hex format and SHA-1 algorithm
  __PACKAGE__->add_columns(
    'password' => {
      data_type     => 'CHAR',
      size          => 40,
      encode_column => 1,
      encode_class  => 'Digest',
      encode_args   => {algorithm => 'SHA-1', format => 'hex'},
  }

  #SHA-1 / hex encoding / generate check method
  __PACKAGE__->add_columns(
    'password' => {
      data_type   => 'CHAR',
      size        => 40 + 10,
      encode_column => 1,
      encode_class  => 'Digest',
      encode_args   => {algorithm => 'SHA-1', format => 'hex', salt_length => 10},
      encode_check_method => 'check_password',
    }
  )

  #MD5 /  base64 encoding / generate check method
  __PACKAGE__->add_columns(
    'password' => {
      data_type => 'CHAR',
      size      => 22,
      encode_column => 1,
      encode_class  => 'Digest',
      encode_args   => {algorithm => 'MD5', format => 'base64'},
      encode_check_method => 'check_password',
    }
  )

  #Eksblowfish bcrypt / cost of 8/ no key_nul / generate check method
  __PACKAGE__->add_columns(
    'password' => {
      data_type => 'CHAR',
      size      => 59,
      encode_column => 1,
      encode_class  => 'Crypt::Eksblowfish::Bcrypt',
      encode_args   => { key_nul => 0, cost => 8 },
      encode_check_method => 'check_password',
    }
  )

(this is copied exactly from the source, bestie β€” 40, 40 + 10, 22, 59, all of it. those numbers matter, don't touch them 😀)

and then, in your actual application code:

   #updating the value.
   $row->password('plaintext');
   my $digest = $row->password;

   #checking against an existing value with a check_method
   $row->check_password('old_password'); #true
   $row->password('new_password');
   $row->check_password('new_password'); #returns true
   $row->check_password('old_password'); #returns false
⚠️ note, and this part is lowkey important: the component needs to be loaded before Core and before other components like Timestamp. Core should always be last. periodt.

like, e.g.:

   E.g:
   __PACKAGE__->load_components(qw/EncodedColumn TimeStamp Core/);

πŸ¦‹ DESCRIPTION πŸ¦‹

this DBIx::Class component is literally the moment: it automatically encodes a column's contents whenever the value of that column gets set. set it β†’ encoded. done. iconic.

now, it's similar to the existing DBIx::Class::DigestColumns, but there are some key differences (and bestie, there are several):

  • "DigestColumns" does the encode operation on "insert" and "update", whereas "EncodedColumn" does it when the value is set, or on "new".
  • "DigestColumns" supports only algorithms of the Digest family.
  • "EncodedColumn" employs a set of thin wrappers around different cipher modules so you get support for any cipher you wish to use β€” and the wrappers are very simple to write (typically less than 30 lines 🫢).
  • "EncodedColumn" supports having more than one encoded column per table, and each column can use a different cipher. multiple icons, no competition.
  • "Encode" adds only one item to the namespace of the object utilizing it ("_column_encoders").

ok and here's the part nobody likes: there are, unfortunately, some features that "EncodedColumn" doesn't support 😭. "DigestColumns" supports changing certain options at runtime, plus the option to not automatically encode values on set. the author of this module found those options non-essential and omitted them by design. so like... not a bug, a choice. πŸ’€


🌸 Options added to add_column 🌸

✨ encode_column => 1 ✨

turns on automatic encoding of column values. if this option isn't set to true, every other option becomes a no-op. like, they just sit there. πŸͺ‘ no notes.

πŸ’– encode_check_method => $method_name πŸ’–

by using the encode_check_method attribute when you declare a column, you can create a check method for that column. the check method accepts a plain text string, and returns a boolean indicating whether the digest of the provided value matches the current value. cute, useful, does exactly what it says on the label. βœ…

πŸ‘‘ encode_class πŸ‘‘

the class to use for encoding. the available classes are:

  • "Crypt::Eksblowfish::Bcrypt" β€” uses DBIx::Class::EncodedColumn::Crypt::Eksblowfish::Bcrypt and requires Crypt::Eksblowfish::Bcrypt to be installed
  • "Digest" β€” uses DBIx::Class::EncodedColumn::Digest and requires Digest to be installed as well as the algorithm required (Digest::SHA, Digest::Whirlpool, etc.)
  • "Crypt::OpenPGP" β€” uses DBIx::Class::EncodedColumn::Crypt::OpenPGP and requires Crypt::OpenPGP to be installed

pls go read the relevant class's documentation for the specific arguments each one accepts, ok? and make sure you include the encoding algorithm (e.g. Crypt::OpenPGP) in your application's requirements. don't skip that part, fr fr πŸ™


🌈 EXTENDED METHODS 🌈

the following DBIx::Class::ResultSource method is extended:

  • register_column β€” handles the options described above.

the following DBIx::Class::Row methods are extended by this module:

  • new β€” encodes the columns on new() so that copy and create DWIM.
  • set_column β€” encodes values whenever the column is set.

πŸ’œ SEE ALSO πŸ’œ

DBIx::Class::DigestColumns, DBIx::Class, Digest β€” go read those next, bestie, they're the whole supporting cast.


πŸŽ€ AUTHOR πŸŽ€

Guillermo Roditi (groditi) <groditi@cpan.org>

inspired by the original module written by Tom Kirkpatrick (tkp) <tkp@cpan.org>, featuring contributions from Guillermo Roditi (groditi) <groditi@cpan.org> and Marc Mims <marc@questright.com>


🫢 CONTRIBUTORS 🫢

  • jshirley β€” J. Shirley <cpan@coldhardcode.com>
  • kentnl β€” Kent Fredric <kentnl@cpan.org>
  • mst β€” Matt S Trout <mst@shadowcat.co.uk>
  • wreis β€” Wallace reis <wreis@cpan.org>

Copyright (c) the DBIx::Class::EncodedColumn "AUTHOR" and "CONTRIBUTORS" as listed above.


🧚 LICENSE 🧚

this library is free software and may be distributed under the same terms as perl itself. periodt. πŸ’…


🌸 ok that's the whole page, you ate that. this beauty is from perl v5.40.1, dated 2025-04-01 β€” so go forth and encode responsibly, bestie. βœ¨πŸ“πŸ’œ
πŸ“¦ where this page comes from