blib/lib/MOBY/collection_output.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 #!/usr/bin/perl -w
2 package MOBY::collection_output;
3 use strict;
4 use Carp;
5 use MOBY::Config;
6 use vars qw($AUTOLOAD @ISA);
7  
8 use vars qw /$VERSION/;
9 $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/;
10  
11 =head1 NAME
12  
13 MOBY::collection_output - a lightweight connection to the
14 collection_output table in the database
15  
16 =head1 SYNOPSIS
17  
18 #NON FUNCTIONAL AT THIS TIME
19
20 use MOBY::collection_output;
21 my $Instance = MOBY::collection_output->new(
22 object_type => "Sequence",
23 namespaces => ["genbank/gi", "genbank/Acc"],
24 article_name => "InputSequenceThingy",
25 );
26  
27  
28 =cut
29  
30 =head1 DESCRIPTION
31  
32 representation of the collection_output 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_output_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_output_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_output(
102 service_instance_lsid => $self->service_instance_lsid,
103 article_name => $self->article_name);
104 return $id;
105 }
106  
107 sub AUTOLOAD {
108 no strict "refs";
109 my ( $self, $newval ) = @_;
110 $AUTOLOAD =~ /.*::(\w+)/;
111 my $attr = $1;
112 if ( $self->_accessible( $attr, 'write' ) ) {
113 *{$AUTOLOAD} = sub {
114 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
115 return $_[0]->{$attr};
116 }; ### end of created subroutine
117 ### this is called first time only
118 if ( defined $newval ) {
119 $self->{$attr} = $newval;
120 }
121 return $self->{$attr};
122 } elsif ( $self->_accessible( $attr, 'read' ) ) {
123 *{$AUTOLOAD} = sub {
124 return $_[0]->{$attr};
125 }; ### end of created subroutine
126 return $self->{$attr};
127 }
128  
129 # Must have been a mistake then...
130 croak "No such method: $AUTOLOAD";
131 }
132 sub DESTROY { }
133 1;