package GO::Object::XrefAbbr; =head1 NAME GO::Object::XrefAbbr - represents a database object =cut use strict; use Data::Dumper; use Exporter; use GO::TestSet qw(dfv_test); use lib '/Users/gwg/go/scratch/tools'; use vars qw(@ISA); use base qw(GO::Object::Base); #GO::MiniTests); use GO::Object::URL; sub _specification { my $self = shift; my @arr = $self->SUPER::_specification; push @arr, ( # required "abbreviation", { test => dfv_test('is_a_string_p'), required => 1, }, "database_name", { test => dfv_test('is_a_string_p'), required => 1, }, "synonym", { allow_multiple => 1, test => dfv_test('is_a_string_p'), }, # "shorthand_name", { # test => 'is_a_string_p', # }, "description", { test => dfv_test('is_a_string_p'), }, "object", { test => dfv_test('is_a_string_p'), # required => 1, }, "example_id", { allow_multiple => 1, test => dfv_test('is_a_string_p'), # required => 1, }, "database_url", { type => 'GO::Object::URL', allow_multiple => 1, test => dfv_test('is_a_subclass_of_p', { class => 'GO::Object::URL', this => 1 }), # required => 1, }, "url_syntax", { allow_multiple => 1, test => [ dfv_test('is_an_url_p'), qr/\[example_id\]/ ], }, "url_example", { allow_multiple => 1, test => dfv_test('is_an_url_p'), }, "anchor", { test => dfv_test('is_a_string_p'), }, ); return @arr; } sub transform_parsed_data { my $self = shift; my $arg_h = shift; my $data_h = $arg_h->{data}; my $spec_h; if ($data_h->{database}) { $data_h->{database_name} = $data_h->{database}; delete $data_h->{database}; } if ($data_h->{generic_url}) { if (!$spec_h->{url_spec}) { $spec_h->{url_spec} = GO::Object::URL->get_spec(); $spec_h->{url_dfv_profile} = GO::Object::URL->dfv_profile(); } if (! ref $data_h->{generic_url}) { $data_h->{generic_url} = [ $data_h->{generic_url} ]; } foreach (@{$data_h->{generic_url}}) { my $results = GO::Object::URL->new({ data => { href => $_ , link_title => ( $data_h->{database_name} || undef ) }, object_spec => $spec_h->{url_spec}, dfv_profile => $spec_h->{url_dfv_profile}, check_input => $arg_h->{check_input} || undef, return_as => 'success_hash', }); push @{$data_h->{database_url}}, $results->{OBJECT} if $results->{SUCCESS}; if ($results->{ERROR_LIST}) { $self->add_message($results->{ERROR_LIST}); #{ OBJ => $results->{OBJECT}, ERRORS => $results->{ERROR_LIST} }); } } delete $data_h->{generic_url}; } return $data_h; } sub add_url { my $self = shift; my $arg_h = shift; if (! ref $arg_h) { # we have a string as the argument $arg_h = { data => { href => $arg_h } }; } my $results = GO::Object::URL->new({ %$arg_h, return_as => 'success_hash', }); if ($results->{SUCCESS}) { # hurrah! if (!$arg_h->{add_as}) { $arg_h->{add_as} = 'url'; } push @{$self->{ $arg_h->{add_as} }}, $results->{OBJECT}; } if ($results->{ERROR_LIST}) { $self->add_message($results->{ERROR_LIST}); } } 1;