File Coverage

blib/lib/DBD/PO/Statement.pm
Criterion Covered Total %
statement 19 21 90.4
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 28 92.8


line stmt bran cond sub pod time code
1             package DBD::PO::Statement;
2            
3 1     1   4086 use strict;
  1         2  
  1         35  
4 1     1   5 use warnings;
  1         3  
  1         37  
5            
6             our $VERSION = '2.09';
7            
8 1     1   6 use DBD::File;
  1         3  
  1         289  
9 1     1   5 use parent qw(-norequire DBD::File::Statement);
  1         3  
  1         6  
10            
11 1     1   81 use Carp qw(croak);
  1         2  
  1         91  
12 1     1   5 use English qw(-no_match_vars $OS_ERROR);
  1         2  
  1         9  
13 1     1   161 use DBD::PO::Text::PO qw($EOL_DEFAULT $SEPARATOR_DEFAULT @COL_NAMES);
  0            
  0            
14            
15             sub open_table { ## no critic (ExcessComplexity)
16             my ($self, $data, $table, $create_mode, $lock_mode) = @_;
17            
18             my $dbh = $data->{Database};
19             my $tables = $dbh->{po_tables};
20             if (! exists $tables->{$table}) {
21             $tables->{$table} = {};
22             }
23             my $meta = $tables->{$table} || {};
24             my $po = $meta->{po} || $dbh->{po_po};
25             if (! $po) {
26             @{ $dbh->FETCH('f_valid_attrs') }{qw(po_eol po_separator po_charset)}
27             = (1) x 3; ## no critic (MagicNumbers)
28             my $class = $meta->{class}
29             || $dbh->{po_class}
30             || 'DBD::PO::Text::PO';
31             my %opts = (
32             eol => exists $meta->{eol}
33             ? $meta->{eol}
34             : exists $dbh->{po_eol}
35             ? $dbh->{po_eol}
36             : $EOL_DEFAULT,
37             separator => exists $meta->{separator}
38             ? $meta->{separator}
39             : exists $dbh->{po_separator}
40             ? $dbh->{po_separator}
41             : $SEPARATOR_DEFAULT,
42             charset => exists $meta->{charset}
43             ? $meta->{charset}
44             : $dbh->{po_charset}
45             ? $dbh->{po_charset}
46             : undef,
47             );
48             $po = $meta->{po}
49             = $class->new(\%opts);
50             }
51             my $file = $meta->{file}
52             || $table;
53             my $tbl = $self->SUPER::open_table($data, $file, $create_mode, $lock_mode);
54             if ($tbl) {
55             {
56             my $po_charset = exists $meta->{charset}
57             ? $meta->{charset}
58             : $dbh->{po_charset}
59             ? $dbh->{po_charset}
60             : undef;
61             if ($po_charset && $tbl->{fh}) {
62             $tbl->{fh}->binmode("encoding($po_charset)")
63             or croak "binmode $OS_ERROR";
64             }
65             }
66             $tbl->{po_po} = $po;
67             my $types = $meta->{types};
68             if ($types) {
69             # The 'types' array contains DBI types, but we need types
70             # suitable for DBD::Text::PO.
71             my $t = [];
72             for (@{$types}) {
73             if ($_) {
74             $_ = $DBD::PO::PO_TYPES[$_ + 6] ## no critic (MagicNumbers)
75             || $DBD::PO::PV;
76             }
77             else {
78             $_ = $DBD::PO::PV;
79             }
80             push @{$t}, $_;
81             }
82             $tbl->{types} = $t;
83             }
84             if (
85             ! $create_mode
86             && ! $self->{ignore_missing_table}
87             && $self->command() ne 'DROP'
88             ) {
89             $tbl->{col_names} = \@COL_NAMES;
90             }
91             }
92            
93             return $tbl;
94             }
95            
96             sub command {
97             return shift->{command};
98             }
99            
100             1;
101            
102             __END__