blib/lib/MOBY/collection_input.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 113 CC 9 SCAR 27.3
CC
9
Cov
0%
new
30.0
AUTOLOAD
30.0
_accessible
2.0
CRAP 15.3
1 package MOBY::collection_input;
2 use strict;
3 use Carp;
4 use MOBY::Config;
5 use vars qw($AUTOLOAD @ISA);
6  
7 use vars qw /$VERSION/;
8 $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
9  
10 =head1 NAME
11  
12 MOBY::collection_input - a lightweight connection to the
13 collection_input table in the database
14  
15 =head1 SYNOPSIS
16  
17 #NON FUNCTIONAL AT THIS TIME
18  
19 use MOBY::collection_input;
20 my $Instance = MOBY::collection_input->new(
21 object_type => "Sequence",
22 namespaces => ["genbank/gi", "genbank/Acc"],
23 article_name => "InputSequenceThingy",
24 );
25  
26  
27  
28 =cut
29  
30 =head1 DESCRIPTION
31  
32 representation of the collection_input table. Can write to the database
33  
34 =head1 AUTHORS
35  
36 Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca)
37  
38  
39 =cut
40  
41 {
42  
43 # Encapsulated:
44 # DATA
45 #___________________________________________________________
46 #ATTRIBUTES
47 my %_attr_data = # DEFAULT ACCESSIBILITY
48 (
49 collection_input_id => [ undef, 'read/write' ],
50 article_name => [ undef, 'read/write' ],
51 service_instance_id => [ undef, 'read/write' ],
52 service_instance_lsid => [ undef, 'read/write' ],
53 dbh => [ undef, 'read/write' ],
54 );
55  
56 #_____________________________________________________________
57 # METHODS, to operate on encapsulated class data
58 # Is a specified object attribute accessible in a given mode
59 sub _accessible {
60 my ( $self, $attr, $mode ) = @_;
61 $_attr_data{$attr}[1] =~ /$mode/;
62 }
63  
64 # Classwide default value for a specified object attribute
65 sub _default_for {
66 my ( $self, $attr ) = @_;
67 $_attr_data{$attr}[0];
68 }
69  
70 # List of names of all specified object attributes
71 sub _standard_keys {
72 keys %_attr_data;
73 }
74 }
75  
76 sub new {
77 my ( $caller, %args ) = @_;
78 my $caller_is_obj = ref($caller);
79 return $caller if $caller_is_obj;
80 my $class = $caller_is_obj || $caller;
81 my $proxy;
82 my $self = bless {}, $class;
83 foreach my $attrname ( $self->_standard_keys ) {
84 if ( exists $args{$attrname} ) {
85 $self->{$attrname} = $args{$attrname};
86 } elsif ($caller_is_obj) {
87 $self->{$attrname} = $caller->{$attrname};
88 } else {
89 $self->{$attrname} = $self->_default_for($attrname);
90 }
91 }
92 my $id = $self->WRITE;
93 $self->collection_input_id($id) if defined $id;
94 return $self;
95 }
96  
97 sub WRITE {
98 my ($self) = @_;
99 $CONFIG ||= MOBY::Config->new; # exported by Config.pm
100 my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobycentral' );
101 my $id = $adaptor->insert_collection_input(service_instance_lsid => $self->service_instance_lsid,
102 article_name => $self->article_name);
103 return $id;
104 }
105  
106 sub AUTOLOAD {
107 no strict "refs";
108 my ( $self, $newval ) = @_;
109 $AUTOLOAD =~ /.*::(\w+)/;
110 my $attr = $1;
111 if ( $self->_accessible( $attr, 'write' ) ) {
112 *{$AUTOLOAD} = sub {
113 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
114 return $_[0]->{$attr};
115 }; ### end of created subroutine
116 ### this is called first time only
117 if ( defined $newval ) {
118 $self->{$attr} = $newval;
119 }
120 return $self->{$attr};
121 } elsif ( $self->_accessible( $attr, 'read' ) ) {
122 *{$AUTOLOAD} = sub {
123 return $_[0]->{$attr};
124 }; ### end of created subroutine
125 return $self->{$attr};
126 }
127  
128 # Must have been a mistake then...
129 croak "No such method: $AUTOLOAD";
130 }
131 sub DESTROY { }
132 1;