1 package CXGN
::Stock
::StockLookup
;
5 CXGN::Stock::StockLookup - a module to lookup stock names by unique name or synonym.
9 my $stock_lookup = CXGN::Stock::StockLookup->new({ schema => $schema} );
14 Looks up stocks ("Stock::Stock") that have a match with the unique name or synonym to the searched name. Provides a count of matching stocks when more than one stock is found. Provides the Stock::Stock object when only a single stock matches.
18 Jeremy D. Edwards (jde22@cornell.edu)
23 use MooseX
::FollowPBP
;
24 use Moose
::Util
::TypeConstraints
;
29 isa
=> 'DBIx::Class::Schema',
33 =head2 predicate has_stock_name(), clearer clear_stock_name(), accessors stock_name()
35 functions to test, clear, set or get the stock name.
39 has
'stock_name' => (isa
=> 'Str', is
=> 'rw', predicate
=> 'has_stock_name', clearer
=> 'clear_stock_name');
41 =head2 function get_stock()
49 my $stock_rs = $self->_get_stock_resultset();
51 if ($stock_rs->count == 1) {
52 $stock = $stock_rs->first;
59 =head2 function get_stock_exact()
61 retrieves the stock row with an exact match to the stock name or synonym
67 my $stock_rs = $self->_get_stock_resultset_exact();
69 if ($stock_rs->count == 1) {
70 $stock = $stock_rs->first;
77 =head2 function get_matching_stock_count()
79 retrieves the number of stocks that match the name (or synonym)
83 sub get_matching_stock_count
{
85 my $stock_name = $self->get_stock_name();
86 my $stock_rs = $self->_get_stock_resultset();
90 my $stock_match_count = $stock_rs->count;
91 if (!$stock_match_count) {
94 if ($stock_match_count == 0) {
97 return $stock_match_count;
100 sub _get_stock_resultset
{
102 my $schema = $self->get_schema();
103 my $stock_name = $self->get_stock_name();
104 my $stock_rs = $schema->resultset("Stock::Stock")
105 ->search({ 'me.is_obsolete' => { '!=' => 't' },
107 'lower(me.uniquename)' => { like
=> lc($stock_name) },
110 'lower(type.name)' => { like
=> '%synonym%' },
111 'lower(stockprops.value)' => { like
=> lc($stock_name) },
116 join => { 'stockprops' => 'type'} ,
123 sub _get_stock_resultset_exact
{
125 my $schema = $self->get_schema();
126 my $stock_name = $self->get_stock_name();
127 my $stock_rs = $schema->resultset("Stock::Stock")
128 ->search({ 'me.is_obsolete' => { '!=' => 't' },
129 'lower(uniquename)' => lc($stock_name),
132 join => { 'stockprops' => 'type'} ,