| 1 | package Db::Mediasurface; | ||
| 2 | $VERSION = '0.03'; | ||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use DBI; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use Db::Mediasurface::ReadConfig; | ||
| 7 | |||
| 8 | sub new | ||
| 9 | { | ||
| 10 | my ($class,%arg) = @_; | ||
| 11 | |||
| 12 | my $self = { | ||
| 13 | _config_file => $arg{config_file} || undef, | ||
| 14 | _config => $arg{config} || undef, | ||
| 15 | _version => undef, | ||
| 16 | _dbh => undef | ||
| 17 | }; | ||
| 18 | |||
| 19 | croak('you must supply either a Db::Mediasurface::ReadConfig object or the path to a configuration file') | ||
| 20 | unless ((defined $self->{_config}) or (defined $self->{_config_file})); | ||
| 21 | |||
| 22 | if (defined $self->{_config_file}) | ||
| 23 | { | ||
| 24 | $self->{_config} = Db::Mediasurface::ReadConfig->new( path=>$self->{_config_file} ); | ||
| 25 | } | ||
| 26 | |||
| 27 | bless $self, $class; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub version | ||
| 31 | { | ||
| 32 | my $self = $_[0]; | ||
| 33 | unless (defined $self->{_version}) | ||
| 34 | { | ||
| 35 | my $sql = "SELECT schemaversion FROM systemdefaults"; | ||
| 36 | $self->_dbi_connect; | ||
| 37 | my $sth = $self->{_dbh}->prepare($sql) or carp("Database prepare error: $DBI::errstr"); | ||
| 38 | $sth->execute or carp("Database execute error: $DBI::errstr"); | ||
| 39 | ($self->{_version}) = ($sth->fetchrow_array); | ||
| 40 | $sth->finish(); | ||
| 41 | } | ||
| 42 | return $self->{_version}; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub _dbi_connect | ||
| 46 | { | ||
| 47 | my $self = $_[0]; | ||
| 48 | unless (defined $self->{_dbh}){ | ||
| 49 | my $data_source = 'DBI:Oracle:'; | ||
| 50 | my $username = $self->{_config}->get_username; | ||
| 51 | my $password = $self->{_config}->get_password; | ||
| 52 | my $attributes = {}; | ||
| 53 | $self->{_dbh} = DBI->connect( $data_source, $username, $password, $attributes ) | ||
| 54 | or croak("Couldn't connect to database: $DBI::errstr"); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||
| 60 | =head1 NAME | ||
| 61 | |||
| 62 | Db::Mediasurface - manipulates a Mediasurface database. | ||
| 63 | |||
| 64 | =head1 VERSION | ||
| 65 | |||
| 66 | This document refers to version 0.03 of DB::Mediasurface, released August 3, 2001. | ||
| 67 | |||
| 68 | =head1 SYNOPSIS | ||
| 69 | |||
| 70 | use Db::Mediasurface; | ||
| 71 | $path = '/opt/ms/3.0/etc/ms.properties'; | ||
| 72 | $ms = Db::Mediasurface->new( config_file=>$path ); | ||
| 73 | print ("Schema version: ".$ms->version."\n"); | ||
| 74 | |||
| 75 | use Db::Mediasurface; | ||
| 76 | use Db::Mediasurface::ReadConfig; | ||
| 77 | $path = '/opt/ms/3.0/etc/ms.properties'; | ||
| 78 | $config = Db::Mediasurface::Readconfig->new( config=>$path ); | ||
| 79 | $ms = Db::Mediasurface->new( config=>$config ); | ||
| 80 | print ("Schema version: ".$ms->version."\n"); | ||
| 81 | |||
| 82 | =head1 DESCRIPTION | ||
| 83 | |||
| 84 | =head2 Overview | ||
| 85 | |||
| 86 | Db::Mediasurface is a wrapper for most other Db::Mediasurface:: modules. At present, only the new() and version() methods are supported. | ||
| 87 | |||
| 88 | =head2 Constructor | ||
| 89 | |||
| 90 | =over 4 | ||
| 91 | |||
| 92 | =item $ms = Db::Mediasurface->new( config=>$config_object ); | ||
| 93 | |||
| 94 | =item $ms = Db::Mediasurface->new( config_file=>$path2config ); | ||
| 95 | |||
| 96 | Create a new Db::Mediasurface object by supplying either the path to a valid Mediasurface configuration file (usually named ms.properties), or a Db::Mediasurface::ReadConfig object. | ||
| 97 | |||
| 98 | =back | ||
| 99 | |||
| 100 | =head2 Methods | ||
| 101 | |||
| 102 | =over 4 | ||
| 103 | |||
| 104 | =item $ms_version = $ms->version; | ||
| 105 | |||
| 106 | Returns the database schema version. | ||
| 107 | |||
| 108 | =back | ||
| 109 | |||
| 110 | =head1 AUTHOR | ||
| 111 | |||
| 112 | Nigel Wetters (nwetters@cpan.org) | ||
| 113 | |||
| 114 | =head1 COPYRIGHT | ||
| 115 | |||
| 116 | Copyright (c) 2001, Nigel Wetters. All Rights Reserved. | ||
| 117 | This module is free software. It may be used, redistributed | ||
| 118 | and/or modified under the same terms as Perl itself. | ||