DBIx::Class handle boolean values ββusing DBIx :: Class :: InflateColumn :: Boolean :
Download this component and declare the columns as booleans.
package Table; __PACKAGE__->load_components(qw/InflateColumn::Boolean Core/); __PACKAGE__->table('table'); __PACKAGE__->true_is('Y'); __PACKAGE__->add_columns( foo => { data_type => 'varchar', is_boolean => 1, }, bar => { data_type => 'varchar', is_boolean => 1, true_is => qr/^(?:yes|ja|oui|si)$/i, }, baz => { data_type => 'int', is_boolean => 1, false_is => ['0', '-1'], }, );
Then you can treat the specified column as a boolean:
print 'table.foo is ', $table->foo ? 'true' : 'false', "\n"; print 'table.bar is ', $table->bar ? 'true' : 'false', "\n";
The boolean object still binds to the actual value of the field:
print $table->foo;
UPD How to select rows whose fields are true
Since DBIx::Class uses SQL::Abstract to search for fields with a value of TRUE , you must call the unary unary operator bool :
my %where = ( -bool => 'is_user', -not_bool => 'is_enabled', );
Would give you:
WHERE is_user AND NOT is_enabled
source share