File Coverage

blib/lib/Video/TeletextDB.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package Video::TeletextDB;
2 1     1   1931 use 5.006001;
  1         4  
  1         49  
3 1     1   6 use strict;
  1         2  
  1         31  
4 1     1   5 use warnings;
  1         2  
  1         36  
5 1     1   6 use Carp;
  1         1  
  1         66  
6 1     1   62 use Video::TeletextDB::Access;
  0            
  0            
7              
8             our $VERSION = "0.02";
9             use base qw(Video::TeletextDB::Parameters);
10              
11             our @CARP_NOT = qw(File::Path
12             Video::TeletextDB::Access Video::TeletextDB::Options
13             Video::TeletextDB::Parameters);
14              
15             sub init {
16             my ($tele, $params) = @_;
17              
18             $tele->{access_class} = "Video::TeletextDB::Access" unless
19             defined($tele->{access_class} = delete $params->{DbClass});
20              
21             $tele->SUPER::init($params);
22             $tele->{access_class}->prepare($tele, $params);
23             }
24              
25             # It's important that you cannot change the cache_dir.
26             # That would make upgrade/downgrade in Video::TeletextDB::Access.pm buggy
27             sub cache_dir {
28             croak 'Too many arguments for cache_dir method' if @_ > 1;
29             return shift->{cache_dir} ||
30             croak "Current access class doesn't support a cache_dir concept";
31             }
32              
33             sub access_class {
34             croak 'Too many arguments for cache_dir method' if @_ > 1;
35             return shift->{access_class};
36             }
37              
38             sub access : method {
39             my $tele = shift;
40             return $tele->access_class->new(parent => $tele, @_);
41             }
42              
43             my %delete_params = map { $_ => 1 } qw(channel umask);
44             sub delete : method {
45             # Abuse the access method to collect properties
46             my ($tele, %params) = @_;
47             my @bad = grep !exists $delete_params{$_}, keys %params;
48             croak("Unknown parameters ", join(", ", @bad)) if @bad;
49             shift->access(%params, acquire => 0, creat => 1)->delete;
50             }
51              
52             1;
53             __END__