/usr/share/perl5/CPANPLUS/Internals/Source/SQLite/Tie.pm is in libcpanplus-perl 0.9152-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | package CPANPLUS::Internals::Source::SQLite::Tie;
use strict;
use warnings;
use CPANPLUS::Error;
use CPANPLUS::Module;
use CPANPLUS::Module::Fake;
use CPANPLUS::Module::Author::Fake;
use CPANPLUS::Internals::Constants;
use Params::Check qw[check];
use Module::Load::Conditional qw[can_load];
use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
use vars qw[@ISA $VERSION];
$VERSION = "0.9152";
require Tie::Hash;
push @ISA, 'Tie::StdHash';
sub TIEHASH {
my $class = shift;
my %hash = @_;
my $tmpl = {
dbh => { required => 1 },
table => { required => 1 },
key => { required => 1 },
cb => { required => 1 },
offset => { default => 0 },
};
my $args = check( $tmpl, \%hash ) or return;
my $obj = bless { %$args, store => {} } , $class;
return $obj;
}
sub FETCH {
my $self = shift;
my $key = shift or return;
my $dbh = $self->{dbh};
my $cb = $self->{cb};
my $table = $self->{table};
### did we look this one up before?
if( my $obj = $self->{store}->{$key} ) {
return $obj;
}
my $res = $dbh->query(
"SELECT * from $table where $self->{key} = ?", $key
) or do {
error( $dbh->error );
return;
};
my $href = $res->hash;
### get rid of the primary key
delete $href->{'id'};
### no results?
return unless keys %$href;
### expand author if needed
### XXX no longer generic :(
if( $table eq 'module' ) {
$href->{author} = $cb->author_tree( $href->{author } ) or return;
}
my $class = {
module => 'CPANPLUS::Module',
author => 'CPANPLUS::Module::Author',
}->{ $table };
my $obj = $self->{store}->{$key} = $class->new( %$href, _id => $cb->_id );
return $obj;
}
sub STORE {
my $self = shift;
my $key = shift;
my $val = shift;
$self->{store}->{$key} = $val;
}
1;
sub FIRSTKEY {
my $self = shift;
my $dbh = $self->{'dbh'};
my $res = $dbh->query(
"select $self->{key} from $self->{table} order by $self->{key} limit 1"
);
$self->{offset} = 0;
my $key = $res->flat->[0];
return $key;
}
sub NEXTKEY {
my $self = shift;
my $dbh = $self->{'dbh'};
my $res = $dbh->query(
"select $self->{key} from $self->{table} ".
"order by $self->{key} limit 1 offset $self->{offset}"
);
$self->{offset} +=1;
my $key = $res->flat->[0];
my $val = $self->FETCH( $key );
### use each() semantics
return wantarray ? ( $key, $val ) : $key;
}
sub EXISTS { !!$_[0]->FETCH( $_[1] ) }
sub SCALAR {
my $self = shift;
my $dbh = $self->{'dbh'};
my $res = $dbh->query( "select count(*) from $self->{table}" );
return $res->flat;
}
### intentionally left blank
sub DELETE { }
sub CLEAR { }
|