ACME-QuoteDB
view release on metacpan or search on metacpan
lib/ACME/QuoteDB.pm view on Meta::CPAN
}
return ($q->update && $atr->update && $ctg->update);
}
sub delete_quote {
my ( $self, $arg_ref ) = @_;
if (not $arg_ref) {croak 'QuoteId required'}
_args_are_valid($arg_ref, [qw/QuoteId/]);
my $q = Quote->retrieve($arg_ref->{'QuoteId'});
#$q->quote($arg_ref->{'QuoteId'});
return $q->delete;
}
sub get_quote {
my ( $self, $arg_ref ) = @_;
# default use case, return random quote from all
if (not $arg_ref) {
return _get_one_rand_quote_from_all;
}
_args_are_valid($arg_ref, [qw/Rating AttrName Source Category/]);
my ($lower, $upper) = (q{}, q{});
if ($arg_ref->{'Rating'}) {
($lower, $upper) = _get_rating_params($arg_ref->{'Rating'});
}
my $attr_name = q{};
if ( $arg_ref->{'AttrName'} ) {
$attr_name = _rm_beg_end_space($arg_ref->{'AttrName'});
}
my $source = q{};
if ( $arg_ref->{'Source'} ) {
$source = _rm_beg_end_space($arg_ref->{'Source'});
}
my $catg; # will become scalar or array ref
if ( $arg_ref->{'Category'} ) {
$catg = _rm_beg_end_space($arg_ref->{'Category'});
}
# use case for attribution, return random quote
my $quotes_ref =
_get_rand_quote_for_attribution($attr_name, $lower,
$upper, q{}, q{}, $source, $catg);
# one random from specified pool
return $quotes_ref->[rand scalar @{$quotes_ref}];
}
# XXX isn't there a method in DBI for this, bind something,...
# TODO follow up
sub _make_correct_num_of_sql_placeholders {
my ($ids) = @_;
# XXX a hack to make a list of '?' placeholders
my @qms = ();
for (1..scalar @{$ids}) {
push @qms, '?';
}
return join ',', @qms;
}
sub get_quotes {
my ( $self, $arg_ref ) = @_;
# default use case, return random quote from all
if (not $arg_ref) {
return _get_one_rand_quote_from_all;
}
_args_are_valid($arg_ref, [qw/Rating AttrName Limit Category Source/]);
my ($lower, $upper) = (q{}, q{});
if ($arg_ref->{'Rating'}) {
($lower, $upper) = _get_rating_params($arg_ref->{'Rating'});
}
my $limit = q{};
if ($arg_ref->{'Limit'}) {
# specify 'n' amount of quotes to limit by
$limit = _rm_beg_end_space($arg_ref->{'Limit'});
}
my $attribution = q{};
if ( $arg_ref->{'AttrName'} ) {
$attribution = _rm_beg_end_space($arg_ref->{'AttrName'});
}
my $source = q{};
if ( $arg_ref->{'Source'} ) {
$source = _rm_beg_end_space($arg_ref->{'Source'});
}
my $catg = q{};
if ( $arg_ref->{'Category'} ) {
$catg = _rm_beg_end_space($arg_ref->{'Category'});
}
# use case for attribution, return random quote
return _get_rand_quote_for_attribution($attribution, $lower,
$upper, $limit, q{}, $source, $catg);
}
sub get_quotes_contain {
my ( $self, $arg_ref ) = @_;
my $contain = q{};
if ($arg_ref->{'Contain'}) {
$contain = _rm_beg_end_space($arg_ref->{'Contain'});
( run in 2.544 seconds using v1.01-cache-2.11-cpan-2398b32b56e )