The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Class::DBI::Plugin::PseudoColumns - an interface to use some pseudo columns

SYNOPSIS

 package Music::CD;
 use base 'Music::DBI';
 
 Music::CD->table('cd');
 Music::CD->columns(All => qw/cdid artist title year reldate properties/);
 use Class::DBI::Plugin::PseudoColumns;
 Music::CD->pseudo_columns(properties => qw/asin tag/);
 
 use Music::CD;
 my $cds = Music::CD->search(artist => 'Steve Vai');
 while (my $cd = $cds->next) {
     if ($cd->title =~ /^Real\s+Illusions/i) {
         $cd->asin('B0007GADZO');
     }
     $cd->tag(['rock', 'guitar', 'tricky play']);
     $cd->update;
 }

DESCRIPTION

This module provides an easy way to use pseudo column in your Class::DBI based table classes. The ``pseudo column'' means a kind of column that is including an optical hashref string (via Data::Dumper). You can get and set with using the pseudo column accessors (same as always). But, you can't use the columns' name into your SQL, SQL interfaced methods, ORDER BY clause and GROUP BY clause, etc. This module is useful when you'd like to add an unimportant column without issuing ALTER TABLE, and when you'd like to have related multiple data without normalizing table.

HOW TO USE

Create a column

You should create a huge size column into your table. like this:

 CREATE TABLE cd (
   cdid int UNSIGNED auto_increment,
   artist varchar(255),
   title varchar(255),
   year int,
   reldate date,
   properties text, # create for using pseudo column
   PRIMARY KEY (cdid)
 );

Create a table class

Almost same as usual.

 package Music::CD;
 use base 'Music::DBI';
 
 Music::CD->table('cd');
 Music::CD->columns(All => qw/cdid artist title year reldate properties/);

Use it

You will be able to use pseudo column with only to use this module.

 use Class::DBI::Plugin::PseudoColumns;

Set your pseudo columns as your like

 Music::CD->pseudo_columns(properties => qw/asin tag/);

METHOD

  • pseudo_columns(parent_colname => ('pseudo_column1'[, 'pseudo_column2' ...]));

    You can set a pseudo columns' name with parent column's name. ``pseudo_column1'' ... will provide to you each pseudo column's accessor.

AUTHOR

Koichi Taniguchi <taniguchi@livedoor.jp>

COPYRIGHT

Copyright (c) 2005 Koichi Taniguchi. Japan. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Class::DBI, Data::Dumper