An Introduction to Class::DBI - Advanced Topics 37

Advanced Topics

Adding extra functionality to your classes

    package AcceptanceSpeech;
    use base 'Class::DBI';
    AcceptanceSpeech->set_db('Main', 'dbi:pg', 'dbi_user', 'dbi_password');
    AcceptanceSpeech->table('acceptance_speech');
    AcceptanceSpeech->columns('id','nomination_id', 'duration', 'laughs');
    AcceptanceSpeech->columns(Primary => 'id');
    sub perceived_duration {
        my $speech = shift;
        my $speaker = $speech->nomination->credit->person;
    return(
        $speech->duration
        - $speaker->popularity
        + ($speaker->vacuity_index / $speech->laughs)
    );
    }

 

YAPC::Canada << Previous | Index | Next >>
Copyright © 2003 Michael Graham