package Vote::DB::Choice;

# $Id$

use strict;
use warnings;
use base 'Vote::DB::common';
use Vote::DB::Poll;

=head1 NAME

Vote::Model::Vote - Catalyst Model

=head1 DESCRIPTION

Catalyst Model.

=cut

sub new {
    my ($class, $dbstring, $key) = @_;
    
    bless {
        key => $key,
        dbstring => $dbstring,
        db => Vote::DB::common::_newdb($dbstring),
    }, $class;
}

sub choicekey { $_[0]->{key} }

sub poll {
    my ($self) = @_;
    Vote::DB::Poll->new($self->{dbstring}, $self->info->{poll});
}

sub info {
    my ($self) = @_;

    my $sth = $self->db->prepare_cached(
        q{
        select * from choice where key = ?
        }
    );
    $sth->execute($self->choicekey);

    my $res = $sth->fetchrow_hashref;
    $sth->finish;
    $res
}

=head1 AUTHOR

Thauvin Olivier

=head1 LICENSE

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

=cut

1;
