DBIx::...Column(3pm)
π 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 beforeCoreand before other components likeTimestamp.Coreshould 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"β usesDBIx::Class::EncodedColumn::Crypt::Eksblowfish::Bcryptand requiresCrypt::Eksblowfish::Bcryptto be installed"Digest"β usesDBIx::Class::EncodedColumn::Digestand requiresDigestto be installed as well as the algorithm required (Digest::SHA,Digest::Whirlpool, etc.)"Crypt::OpenPGP"β usesDBIx::Class::EncodedColumn::Crypt::OpenPGPand requiresCrypt::OpenPGPto 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 onnew()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 β
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
- debian trixie: libdbix-class-encodedcolumn-perl 0.00020-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-class-encodedcolumn-perl 0.00020-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-class-encodedcolumn-perl 0.00020-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms