File Coverage

blib/lib/Bio/ConnectDots/Connector.pm
Criterion Covered Total %
statement 43 44 97.7
branch 10 18 55.5
condition 7 16 43.7
subroutine 9 9 100.0
pod 0 5 0.0
total 69 92 75.0


line stmt bran cond sub pod time code
1             package Bio::ConnectDots::Connector;
2 4     4   53081 use vars qw(@ISA @AUTO_ATTRIBUTES @OTHER_ATTRIBUTES %SYNONYMS);
  4         10  
  4         315  
3 4     4   25 use strict;
  4         7  
  4         127  
4 4     4   4963 use Class::AutoClass;
  4         116763  
  4         2661  
5             @ISA = qw(Class::AutoClass); # AutoClass must be first!!
6              
7             @AUTO_ATTRIBUTES=qw(connectorset dots db_id
8             _dots);
9             @OTHER_ATTRIBUTES=qw();
10             %SYNONYMS=();
11             Class::AutoClass::declare(__PACKAGE__);
12              
13             sub _init_self {
14 4     4   3599 my($self,$class,$args)=@_;
15 4 50       18 return unless $class eq __PACKAGE__; # to prevent subclasses from re-running this
16 4         124 my $connectorset=$self->connectorset;
17 4   33     61 my $dots_hash=$args->dots_hash || ($connectorset && $connectorset->dots_hash);
18 4 50       165 $self->put_dots($dots_hash) if $dots_hash;
19             }
20             sub name {
21 3     3 0 68 my($self)=@_;
22 3         75 $self->connectorset->name;
23             }
24             sub put {
25 3     3 0 25 my($self,$label,$dot)=@_;
26 3   66     74 my $dots=$self->dots || $self->dots({});
27 3   50     87 my $dot_list=$dots->{$label} || ($dots->{$label}=[]);
28 3         20 push(@$dot_list,$dot);
29             }
30             sub labels {
31 2     2 0 302 my($self)=@_;
32 2   33     49 my $dots=$self->dots || $self->dots({});
33 2         17 my @labels=keys %$dots;
34 2 100       10 wantarray? @labels: \@labels;
35             }
36             sub get_dots {
37 1     1 0 6 my($self,$label)=@_;
38 1   33     21 my $dots=$self->dots || $self->dots({});
39 1   50     9 my $dots_list=$dots->{$label} || [];
40 1 50       2 unless (defined $dots_list) {
41 0         0 print "break here\n";
42             }
43 1 50       5 wantarray? @$dots_list: $dots_list;
44             }
45              
46             sub put_dots {
47 1     1 0 49 my $self=shift;
48 1 50       4 return {} unless @_;
49 1 50       7 my $dots_hash=@_==1? $_[0]: {@_};
50 1         29 my $connectorset=$self->connectorset;
51 1         31 my $label2dotset=$connectorset->label2dotset;
52 1         11 while (my($label,$ids)=each %$dots_hash) {
53 2         5 my $dotset=$label2dotset->{$label};
54 2 50       5 $self->throw("label $label not valid for ConnectorSet ".$connectorset->name) unless $dotset;
55 2 50       8 $ids=[$ids] unless 'ARRAY' eq ref $ids;
56 2         3 my $dots;
57 2         5 for my $id (@$ids) {
58 2         12 my $dot=$dotset->lookup($id);
59 2         9 $dot->put($self);
60 2         9 $self->put($label,$dot);
61             }
62             }
63             }
64             1;
65             __END__