[Dbix-class] Pseudo columns
Lee Standen
nom at standen.id.au
Thu Oct 26 05:38:49 BST 2006
Looked at working on bitwise fields?
I assume it's using 1, 2 & 4 as values, much like Linux uses for rwx
permissions.
This should do the trick, although you could probably condense it a bit
:) Check out
http://www.perl.com/doc/manual/html/pod/perlop.html#Bitwise_Or_and_Exclusive_Or
for info on the bitwise operators.
sub show_headline {
my $self = shift;
if (@_>0) {
if ($_[0]) {
$self->story_text_used( $self->story_text_used ^ 4 );
} else {
$self->story_text_used( $self->story_text_used | 4 );
}
}
return $self->story_text_used & 4;
}
sub show_synopsis {
my $self = shift;
if (@_>0) {
if ($_[0]) {
$self->story_text_used( $self->story_text_used ^ 2 );
} else {
$self->story_text_used( $self->story_text_used | 2 );
}
}
return $self->story_text_used & 2;
}
sub show_comment {
my $self = shift;
if (@_>0) {
if ($_[0]) {
$self->story_text_used( $self->story_text_used ^ 1 );
} else {
$self->story_text_used( $self->story_text_used | 1 );
}
}
return $self->story_text_used & 1;
}
Paul Makepeace wrote:
> I have a legacy database that encodes three booleans into an integer,
> 0-7. I've like to present three accessors alongside the other columns
> that map to that integer. If I can automagically update it all the
> better.
>
> So I have,
>
> $chart->story_text_used() # 0-7, real database column
>
> and would prefer
>
> $chart->show_headline() # 0,1; not in the db
> $chart->show_synopsis() # ditto
> $chart->show_comment() # ditto
>
> One thought was: I see there's an example of overriding store_column
> in the cookbook, presumably I'd need to override override get_column
> as well?
>
> Or is there another way?
>
> In particular, I'd like to be able to say "these are non-DB-backed
> columns" and instantiate them on the fly rather than necessarily
> putting them in the schema class. So e.g. in a Cat controller I could
> make a couple of columns on the fly that the template could use just
> as another column. Is this possible? I know it sounds kind of horrible
> but it would at the very least help debugging.
>
> Thanks,
> Paul
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>
More information about the DBIx-Class
mailing list