GBPVR-CDBI

 view release on metacpan or  search on metacpan

lib/GBPVR/CDBI.pm  view on Meta::CPAN

package GBPVR::CDBI;

use warnings;
use strict;

our $VERSION = '0.04';

use base 'Class::DBI';
use Win32::TieRegistry;
use File::Spec;

our $gbpvr_dir = $Registry->{'LMachine\software\devnz\GBPVR InstallDir'} || 'C:\program files\devnz\gbpvr';

__PACKAGE__->db_setup(file => 'gbpvr.mdb');

sub db_setup {
  my $self = shift;
  my $p = { @_ };
  my $file = $p->{file};
  $file = File::Spec->rel2abs($file, $gbpvr_dir);  # if file was a relative path, make it full with respect to GBPVR
  my $dbopts = $p->{dbopts} || { AutoCommit=>0, LongTruncOk => 1, LongReadLen => 255 };
  my $dsn = 'driver=Microsoft Access Driver (*.mdb);dbq=' . $file;
  my $rc;
  # trap errors, specifically for the case that GBPVR isn't installed so the
  # default mdb's don't exist (e.g. for cpan-testers)
  eval { $rc = $self->set_db('Main', "dbi:ODBC:$dsn", '', '', $dbopts ); };
  warn "ERROR in db_setup('$file'): $@" if $@;
  return $rc;
}

1;
__END__

=pod

=head1 NAME

GBPVR::CDBI - Database Abstraction for GBPVR

=head1 VERSION

Version 0.04

=head1 SYNOPSIS

Example to search the program listings:

        use GBPVR::CDBI::Programme;
        my @rows = GBPVR::CDBI::Programme->search_like(name => 'Star%');

Example to display the recorded shows:

        use GBPVR::CDBI::RecordingSchedule;
        my @rows = GBPVR::CDBI::RecordingSchedule->search(status => 2);
        foreach my $row (@rows){
          printf "-----------------------\n";
          printf "%s - '%s'\n", $row->programme_oid->name, $row->programme_oid->sub_title;
          printf "<%s>\n", $row->filename;
          printf "   %s\n", $row->programme_oid->description;
        }

Example to show pending shows (yes, you should be able to order_by via search() and not have to call sort):

        use GBPVR::CDBI::RecordingSchedule;
        my @rows = GBPVR::CDBI::RecordingSchedule->search(status => 0);
        @rows = sort { $a->manual_start_time cmp $b->manual_start_time } @rows;
        foreach my $row (@rows){
          printf "%-20s %8s %s - '%s'\n",
                $row->manual_start_time,
                $row->programme_oid->channel_oid->name,
                $row->programme_oid->name,
                $row->programme_oid->sub_title;



( run in 3.863 seconds using v1.01-cache-2.11-cpan-364913b4093 )