File Coverage

blib/lib/Bio/ConnectDots/DB/DotSet.pm
Criterion Covered Total %
statement 15 38 39.4
branch 0 14 0.0
condition n/a
subroutine 5 7 71.4
pod 1 2 50.0
total 21 61 34.4


line stmt bran cond sub pod time code
1             package Bio::ConnectDots::DB::DotSet;
2 2     2   13 use vars qw(@ISA @AUTO_ATTRIBUTES @OTHER_ATTRIBUTES %SYNONYMS);
  2         4  
  2         166  
3 2     2   11 use strict;
  2         5  
  2         66  
4 2     2   10 use DBI;
  2         19  
  2         103  
5 2     2   11 use Class::AutoClass;
  2         4  
  2         49  
6 2     2   3950 use Bio::ConnectDots::DotSet;
  2         45  
  2         2682  
7             @ISA = qw(Class::AutoClass);
8              
9             @AUTO_ATTRIBUTES=qw(db);
10             @OTHER_ATTRIBUTES=qw();
11             %SYNONYMS=();
12             Class::AutoClass::declare(__PACKAGE__);
13              
14             # store one DotSet. store db_id in object
15             sub put {
16 0     0 0   my($class,$dotset)=@_;
17 0 0         return if $dotset->db_id; # object is already in database
18 0           my $db=$dotset->db;
19 0 0         $class->throw("Cannot put data: database is not connected") unless $db->is_connected;
20 0 0         $class->throw("Cannot put data: database does not exist") unless $db->exists;
21 0           my $name=$dotset->name;
22 0           my $dbh=$db->dbh;
23 0           my $sql=qq(INSERT INTO dotset (name) VALUES ('$name'));
24 0           $db->do_sql($sql);
25 0           my $db_id=$dbh->selectrow_array(qq(SELECT MAX(dotset_id) FROM dotset));
26 0           $dotset->db_id($db_id);
27 0           $dotset;
28             }
29             # fetch one DotSet. return object
30             sub get {
31 0     0 1   my($class,$dotset)=@_;
32 0 0         return $dotset if $dotset->db_id; # already fetched
33 0           my $db=$dotset->db;
34 0 0         $class->throw("Cannot get data: database is not connected") unless $db->is_connected;
35 0 0         $class->throw("Cannot get data: database does not exist") unless $db->exists;
36 0           my $name=$dotset->name;
37 0           my $dbh=$db->dbh;
38 0           my $sql=qq(SELECT name,dotset_id FROM dotset WHERE name='$name');
39 0           my ($name,$db_id)=$dbh->selectrow_array($sql);
40 0 0         return undef unless defined $name;
41 0           return new Bio::ConnectDots::DotSet(-name=>$name,-db_id=>$db_id,-db=>$db);
42             }
43              
44             1;