fixing a problem with empty/duplicated roles upon account creation
[cxgn-corelibs.git] / lib / MOBY / simple_output.pm
blobd6a170979b8c4568aecbbdf68bf865be12cf4708
1 #!/usr/bin/perl -w
2 package MOBY::simple_output;
3 use strict;
4 use Carp;
5 use MOBY::Config;
6 use vars qw($AUTOLOAD @ISA);
8 =head1 NAME
10 MOBY::simple_output - a lightweight connection to the
11 simple_output table in the database
13 =head1 SYNOPSIS
15 NON FUNCTIONAL AT THIS TIME
16 use MOBY::simple_output;
17 my $Instance = MOBY::simple_output->new(
18 object_type => "Sequence",
19 namespaces => ["genbank/gi", "genbank/Acc"],
20 article_name => "InputSequenceThingy",
22 print $Instance->simple_output_id;
23 print $Instance->service_instance_id;
26 =cut
28 =head1 DESCRIPTION
30 representation of the simple_output table. Can write to the database
32 =head1 AUTHORS
34 Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca)
37 =cut
41 # Encapsulated:
42 # DATA
43 #___________________________________________________________
44 #ATTRIBUTES
45 my %_attr_data = # DEFAULT ACCESSIBILITY
47 simple_output_id => [ undef, 'read/write' ],
48 object_type_uri => [ undef, 'read/write' ],
49 namespace_type_uris => [ undef, 'read/write' ],
50 article_name => [ undef, 'read/write' ],
51 service_instance_id => [ undef, 'read/write' ],
52 service_instance_lsid => [ undef, 'read/write' ],
53 collection_output_id => [ undef, 'read/write' ],
54 dbh => [ undef, 'read/write' ],
57 #_____________________________________________________________
58 # METHODS, to operate on encapsulated class data
59 # Is a specified object attribute accessible in a given mode
60 sub _accessible {
61 my ( $self, $attr, $mode ) = @_;
62 $_attr_data{$attr}[1] =~ /$mode/;
65 # Classwide default value for a specified object attribute
66 sub _default_for {
67 my ( $self, $attr ) = @_;
68 $_attr_data{$attr}[0];
71 # List of names of all specified object attributes
72 sub _standard_keys {
73 keys %_attr_data;
77 sub new {
78 my ( $caller, %args ) = @_;
79 my $caller_is_obj = ref($caller);
80 return $caller if $caller_is_obj;
81 my $class = $caller_is_obj || $caller;
82 my $proxy;
83 my $self = bless {}, $class;
84 foreach my $attrname ( $self->_standard_keys ) {
85 if ( exists $args{$attrname} ) {
86 $self->{$attrname} = $args{$attrname};
87 } elsif ($caller_is_obj) {
88 $self->{$attrname} = $caller->{$attrname};
89 } else {
90 $self->{$attrname} = $self->_default_for($attrname);
93 my $id = $self->WRITE;
94 $self->simple_output_id($id) if defined $id;
95 return $self;
98 sub WRITE {
99 my ($self) = @_;
100 $CONFIG ||= MOBY::Config->new; # exported by Config.pm
101 my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobycentral' );
102 my $id = $adaptor->insert_simple_output(
103 object_type_uri => $self->object_type_uri,
104 namespace_type_uris => $self->namespace_type_uris,
105 article_name => $self->article_name,
106 service_instance_lsid => $self->service_instance_lsid,
107 collection_output_id => $self->collection_output_id
109 return $id;
112 sub AUTOLOAD {
113 no strict "refs";
114 my ( $self, $newval ) = @_;
115 $AUTOLOAD =~ /.*::(\w+)/;
116 my $attr = $1;
117 if ( $self->_accessible( $attr, 'write' ) ) {
118 *{$AUTOLOAD} = sub {
119 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
120 return $_[0]->{$attr};
121 }; ### end of created subroutine
122 ### this is called first time only
123 if ( defined $newval ) {
124 $self->{$attr} = $newval;
126 return $self->{$attr};
127 } elsif ( $self->_accessible( $attr, 'read' ) ) {
128 *{$AUTOLOAD} = sub {
129 return $_[0]->{$attr};
130 }; ### end of created subroutine
131 return $self->{$attr};
134 # Must have been a mistake then...
135 croak "No such method: $AUTOLOAD";
137 sub DESTROY { }