view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
# Note: this file was auto-generated by Module::Build::Compat version 0.2808_01
unless (eval "use Module::Build::Compat 0.02; 1" ) {
print "This module requires Module::Build to install itself.\n";
require ExtUtils::MakeMaker;
my $yn = ExtUtils::MakeMaker::prompt
(' Install Module::Build now from CPAN?', 'y');
unless ($yn =~ /^y/i) {
die " *** Cannot install without Module::Build. Exiting ...\n";
}
require Cwd;
lib/ACME/QuoteDB.pm view on Meta::CPAN
($lower, $upper) = _get_if_rating($lower, $upper);
if ($contain) { $contain = qq/ AND quote LIKE '%$contain%' / }
if ($limit) { $limit = qq/ LIMIT '$limit' / };
my @q = Quote->retrieve_from_sql(
qq{ $attr_name $lower $upper $source $qids $contain $limit },
@{$ids}
);
# XXX code duplication but smaller footprint
# choosing not less code duplication, we'll see,...
#my $quotes_ref = [];
#foreach my $q_obj ( @q ){
# next unless $q_obj->quote;
# my $record = Attr->retrieve($q_obj->attr_id);
# my $attr_name = $record->name || q{};
# push @{ $quotes_ref }, $q_obj->quote . "\n-- $attr_name";
#}
#return _get_quote_ref_from_all(\@q);
# XXX array_ref does not work here!
lib/ACME/QuoteDB.pm view on Meta::CPAN
Version 0.1.2
=head1 SYNOPSIS
Easy access to a collection of quotes (the 'Read' part)
As quick one liner:
# randomly display one quote from all available. (like motd, 'fortune')
perl -MACME::QuoteDB -le 'print quote()'
# Say you have populated your quotes database with some quotes from
# 'The Simpsons'
# randomly display one quote from all available for person 'Ralph'
perl -MACME::QuoteDB -le 'print quote({AttrName => "ralph"})'
# example of output
Prinskipper Skippel... Primdable Skimpsker... I found something!
-- Ralph Wiggum
# get 1 quote, only using these categories (you have defined)
perl -MACME::QuoteDB -le 'print quote({Category => [qw(Humor Cartoon ROTFLMAO)]})'
In a script/module, OO usage:
use ACME::QuoteDB;
my $sq = ACME::QuoteDB->new;
# get random quote from any attribution
print $sq->get_quote;
# get random quote from specified attribution
print $sq->get_quote({AttrName => 'chief wiggum'});
# example of output
I hope this has taught you kids a lesson: kids never learn.
-- Chief Wiggum
# get all quotes from one source
print @{$sq->get_quotes({Source => 'THE SimPSoNs'})}; # is case insensitive
# get 2 quotes, with a low rating that contain a specific string
print @{$sq->get_quotes_contain({
Contain => 'til the cow',
Rating => '1-5',
Limit => 2
})};
# get 5 quotes from given source
print @{$sq->get_quotes({Source => 'The Simpsons',
Limit => 5
})};
# list all sources
print $sq->list_attr_sources;
# list all categories
print $sq->list_categories;
=head1 DESCRIPTION
This module provides an easy to use programmitic interface
to a database (sqlite3 or mysql) of 'quotes'. (any content really,
that can fit into our L<"defined format"|/"record format">)
For simplicty you can think of it as a modern fancy perl version
of L<fortune|/fortune>
lib/ACME/QuoteDB.pm view on Meta::CPAN
=back
=head4 Examples of L<Read|/Read>
my $sq = ACME::QuoteDB->new;
# on Oct 31st, one could get an appropriate (humorous) quote:
# (providing, of course that you have defined/populated these categories)
print $sq->get_quote({Category => [qw(Haloween Humor)]});
# get everthing from certain attributor:
print @{$sq->get_quotes({AttrName => 'comic book guy'})};
# get all quotes with a certain rating
$sq->get_quotes({Rating => '7.0'});
# get all quotes containing some specific text:
$sq->get_quotes_contain({Contain => 'til the cow'});
=head4 Examples of L<Create|/Create>
lib/ACME/QuoteDB.pm view on Meta::CPAN
Also see L<ACME::QuoteDB::LoadDB>
=head1 USAGE
use ACME::QuoteDB;
my $sq = ACME::QuoteDB->new;
print $sq->get_quote;
# examples are based on quotes data in the test database.
# (see tests t/data/)
# get specific quote based on basic text search.
# search all 'ralph' quotes for string 'wookie'
print $sq->get_quotes_contain({
Contain => 'wookie',
AttrName => 'ralph',
Limit => 1 # only return 1 quote (if any)
});
# output:
I bent my wookie.
-- Ralph Wiggums
# returns all quotes attributed to 'ralph', with a rating between
# (and including) 7 to 9
print join "\n", @{$sq->get_quotes({
AttrName => 'ralph',
Rating => '7-9'
})
};
# same thing but limit to 2 results returned
# (and including) 7 to 9
print join "\n", @{$sq->get_quotes({
AttrName => 'ralph',
Rating => '7-9',
Limit => 2
})
};
# get 6 random quotes (any attribution)
foreach my $q ( @{$sq->get_quotes({Limit => 6})} ) {
print "$q\n";
}
# get list of available attributions (that have quotes provided by this module)
print $sq->list_attr_names;
# any unique part of name will work
# i.e these will all return the same results (because of our limited
# quotes db data set)
print $sq->get_quotes({AttrName => 'comic book guy'});
print $sq->get_quotes({AttrName => 'comic book'});
print $sq->get_quotes({AttrName => 'comic'});
print $sq->get_quotes({AttrName => 'book'});
print $sq->get_quotes({AttrName => 'book guy'});
print $sq->get_quotes({AttrName => 'guy'});
# get all quotes, only using these categories (you have defined)
print @{$sq->get_quotes({ Category => [qw(Humor ROTFLMAO)] })};
# get all quotes from Futurama
print @{$sq->get_quotes({Source => Futurama})};
Also see t/02* included with this distribution.
(available from the CPAN if not included on your system)
=head1 SUBROUTINES/METHODS
For the most part this is an OO module. There is one function (quote) provided
for command line 'one liner' convenience.
=head2 quote
returns one quote. (is exported).
this takes identical arguments to 'get_quote'. (see below)
example:
perl -MACME::QuoteDB -le 'print quote()'
=head2 new
instantiate a ACME::QuoteDB object.
takes no arguments
# example
my $sq = ACME::QuoteDB->new;
=head2 get_quote
returns one quote
# get random quote from any attribution
print $sq->get_quote;
# get random quote from specified attribution
print $sq->get_quote({AttrName => 'chief wiggum'});
Optional arguments, a hash ref.
available keys: AttrName, Rating
my $args_ref = {
AttrName => 'chief wiggum'
Rating => 7,
};
print $sq->get_quote($args_ref);
Note: The 'Rating' option is very subjective.
It's a 0-10 scale of 'quality' (or whatever you decide it is)
To get a list of the available AttrNames use the list_attr_names method
listed below.
Any unique part of name will work
Example, for attribution 'comic book guy'
# these will all return the same results
print $sq->get_quotes({AttrName => 'comic book guy'});
print $sq->get_quotes({AttrName => 'comic book'});
print $sq->get_quotes({AttrName => 'comic'});
print $sq->get_quotes({AttrName => 'book'});
print $sq->get_quotes({AttrName => 'book guy'});
print $sq->get_quotes({AttrName => 'guy'});
# However, keep in mind the less specific the request is the more results
# are returned, for example the last one would match, 'Comic Book Guy',
# 'Buddy Guy' and 'Guy Smiley',...
=begin comment
# XXX this is a bug with sub _get_attribution_ids_from_name
#print $sq->get_quotes({AttrName => 'guy'}); would not match 'Guy Smiley'
=end comment
=head2 add_quote
Adds the supplied record to the database
possible Key arguments consist of:
Quote, AttrName, Source, Rating, Category
lib/ACME/QuoteDB.pm view on Meta::CPAN
(only useful for then doing an L</update> or L</delete>
possible Key arguments consist of: Quote
my $q = 'Lois: Peter, what did you promise me?' .
"\nPeter: That I wouldn't drink at the stag party." .
"\nLois: And what did you do?" .
"\nPeter: Drank at the stag pa-- ... Whoa. I almost walked into that one.";
my $qid = $sq->get_quote_id({Quote => $q});
print $qid; # 30
=head2 delete_quote (very beta)
deletes an existing quote in the database
takes an valid quote id (see L</get_quote_id>)
possible Key arguments consist of: QuoteId
$sq->delete_quote({QuoteId => $qid});
lib/ACME/QuoteDB.pm view on Meta::CPAN
=head2 get_quotes
returns zero or more quote(s)
Optional arguments, a hash ref.
available keys: AttrName, Rating, Limit
# returns 2 ralph wiggum quotes with a rating between
# (and including) 7 to 9
print join "\n", @{$sq->get_quotes({
AttrName => 'ralph',
Rating => '7-9',
Limit => 2
})
};
AttrName and Rating work exactely the same as for get_quote (docs above)
Limit specifies the amout of results you would like returned. (just like
with SQL)
=head2 get_quotes_contain
returns zero or more quote(s), based on a basic text search.
# get specific quote based on basic text search.
# search all ralph wiggum quotes for string 'wookie'
print $sq->get_quotes_contain({
Contain => 'wookie',
AttrName => 'ralph',
Limit => 1 # only return 1 quote (if any)
})->[0]; # q{Ralph: I bent my wookie.};
Optional arguments, a hash ref.
available keys: AttrName, Contain, Limit
lib/ACME/QuoteDB.pm view on Meta::CPAN
Contain is a simple text string only. Regex not supported
Contain literally becomes: AND quote LIKE '%$contain%'
=head2 list_attr_names
returns a list of attributions (name) for which we have quotes.
# get list of available attributions (that have quotes provided by this module)
print $sq->list_attr_names;
=head2 list_categories
returns a list of categories defined in the database
# get list of available categories (that have quotes provided by this module)
print $sq->list_categories;
=head2 list_attr_sources
returns a list of attribution sources defined in the database
# get list of attribution sources (that have quotes provided by this module)
print $sq->list_attr_sources;
=head1 LOADING QUOTES
In order to actually use this module, one has to load quotes content,
hopefully this is relativly easy,... (see t/01-load_quotes.t in tests)
=over 4
=item 1 add_quote, one record at a time, probably within an iteration loop
lib/ACME/QuoteDB.pm view on Meta::CPAN
=head1 AUTHOR
David Wright, C<< <david_v_wright at yahoo.com> >>
=head1 TODO
=over 2
=item 1 if the database cannot be found, no error is printed!!!
or if you have no write access to it!
"you'll just get 'no attribute can be found,,...", which is cryptic to say
the least!
=item 1 add a dump backup to csv
a backup mechanism for your db to a regular text csv file.
=item 1 clean up tests 'skip if module X' not installed
lib/ACME/QuoteDB.pm view on Meta::CPAN
=head1 ERRATA
Q: Why did you put it in the ACME namespace?
A: Seemed appropriate. I emailed modules@cpan.org and didn't get a
different reaction.
Q: Why did you write this?
A: At a past company, a team I worked on a project with had a test suite,
in which at the completion of successful tests (100%), a 'wisenheimer'
success message would be printed. (Like a quote or joke or the like)
(Interestingly, it added a 'fun' factor to testing, not that one is needed
of course ;). It was hard to justify spending company time to find and
add decent content to the hand rolled process, this would have helped.
Q: Don't you have anything better to do, like some non-trivial work?
A: Yup
Q: Hey Dood! why are u uzing Class::DBI as your ORM!? Haven't your heard
of L<DBIx::Class>?
A: Yup, and I'm aware of 'the new hotness' L<Rose::DB>. If you use this
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
if ($value) {
$self->{record}->{$field} = $value;
}
return $self;
}
sub debug_record {
my ($self) = @_;
print Dumper $self->{record};
return;
}
sub get_record {
my ($self, $field) = @_;
if (not $field){return $self}
return $self->{record}->{$field};
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
$csv->column_names (@QUOTE_FIELDS);
open my $source, '<:encoding(utf8)', $file || croak $!;
_confirm_header_order($csv->getline_hr($source));
while (my $hr = $csv->getline_hr($source)) {
next unless $hr->{quote} and $hr->{name};
if ($self->{verbose}){
print "\n",
'Quote: ', $hr->{quote},"\n",
'Name: ', $hr->{name},"\n",
'Source: ', $hr->{source},"\n",
'Category:', $hr->{catg},"\n",
'Rating: ', $hr->{rating},"\n\n";
};
$self->set_record(quote => $hr->{quote});
$self->set_record(name => $hr->{name});
$self->set_record(source => ($self->{attr_source} || $hr->{source}));
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
return $catg_id;
}
#TODO : refactor
sub write_record {
my ($self) = @_;
$self->_to_utf8;
if ($self->{verbose} and $self->get_record('name')){
print 'Attribution Name: ',$self->get_record('name'),"\n";
};
my $attr_id = $self->_get_id_if_attr_name_exist;
# nope, ok, add them
if (not $attr_id) { # attribution record does not already exist,
# create new entry
if ($self->{write_db}) {
$attr_id = Attr->insert({
name => $self->get_record('name'),
});
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
$self->{success} ||= $flag;
return $self->{success};
};
sub _display_vals_if_verbose {
my ($self) = @_;
if ($self->{verbose}){
#print 'Quote: ', $self->get_record('quote'),"\n";
#print 'Source: ', $self->get_record('source'),"\n";
#print 'Category: ',$self->get_record('catg'),"\n";
#print 'Rating: ', $self->get_record('rating'),"\n";
print Dumper $self->{record};
}
return $self;
}
#sub create_db {
# my ($self) = @_;
#
# if ($self->{db} and $self->{host}) {
# $self->create_db_mysql();
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
load a csv file to quotes database
my $load_db = ACME::QuoteDB::LoadDB->new({
file => '/home/me/data/simpsons_quotes.csv',
file_format => 'csv',
});
$load_db->data_to_db;
print $load_db->success; # bool
header columns of the csv file as follows:
"Quote", "Attribution Name", "Attribution Source", "Category", "Rating"
=head1 DESCRIPTION
This module is part of L<ACME::QuoteDB>. This is a Database loader, it
takes (quotes) data and loads into a database
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
"Sideshow Bob has no decency. He called me Chief Piggum. (laughs) Oh wait, I get it, he's all right.","Chief Wiggum","The Simpsons","Humor",8
my $load_db = ACME::QuoteDB::LoadDB->new({
file => dirname(__FILE__).'/data/simpsons_quotes.csv',
file_format => 'csv',
});
$load_db->data_to_db;
if (!$load_db->success){print 'failed'}
=head3 load from any source
If those dont catch your interest, ACME::QuoteDB::LoadDB is sub-classable,
so one can extract data anyway they like and populate the db themselves.
(there is a test that illustrates overriding the stub method, 'dbload')
you need to populate a record data structure:
lib/ACME/QuoteDB/LoadDB.pm view on Meta::CPAN
# provide a attr_source for all (if not in data)
# data is used first, if not defined use below
attr_source => 'Things Randomly Overheard',
# provide a category for all (if not in data)
category => 'Humor',
# provide a rating for all
rating => 5, # scale 1-10
});
$load_db->data_to_db;
if (!$load_db->success){print 'failed'}
Also see t/01-load_quotes.t included with the distribution.
(available from the CPAN if not included on your system)
=head1 SUBROUTINES/METHODS
This is an Object Oriented module. There is no proceedural interface.
t/data/python_quotes.txt view on Meta::CPAN
PSA felt it would be wise to licencing the Python name to forestall any
lawsuits. An added benefit is that John Cleese is teaching Guido how to walk
funny.
(3) Pre-Release vacations are spent in the Catskills. Post-Release
vacations are spent in the Bahamas. Guido is currently working on a system
which will allow him to make more releases of Python; thus octupling the number
of vacations he takes in a year.
-- Matthew Lewis Carroll Smith, 4 Apr 1997
I mean, just take a look at Joe Strout's brilliant little "python for
beginners" page. Replace all print-statements with sys.stdout.write(
string.join(map(str, args)) + "\n") and you surely won't get any new beginners.
And That Would Be A Very Bad Thing.
-- Fredrik Lundh, 27 Aug 1996
Ya, ya, ya, except ... if I were built out of KSR chips, I'd be running at 25
or 50 MHz, and would be wrong about ALMOST EVERYTHING almost ALL THE TIME just
due to being a computer! Think about it -- when's the last time you spent 20
hours straight debugging your son/wife/friend/neighbor/dog/ferret/snake? And
they *still* fell over anyway? Except in a direction you've never seen before
each time you try it? The easiest way to tell you're dealing with a computer is
t/data/python_quotes.txt view on Meta::CPAN
... and at a higher conceptual level involving graph theoretical transforms of
automata (which I got thanks to Jean Gallier by word of mouth and effort of
chalk) ...
-- Aaron Watters, 17 Sep 1998
Every clarity vanished? :-)
-- Christian Tismer after answering a poster's question, 17 Sep 1998
Take the "public" modifier off Joseph's interface, or leave it there but
nest the interface inside class "closure", or even move the interface to its
own printer.java file, and it compiles and runs without incident. Most of the
big boys I hang with aren't paralyzed by self-explanatory compiler msgs <wink>.
not-to-mention-the-girls-ly y'rs
-- Tim Peters, 24 Sep 1998
<shakes head ruefully> You kids today, with your piercings and your big pants
and your purple-and-green hair and your X-Files and your Paula Cole and your
espresso coffee and your Seattle grunge rock and your virtual machines and your
acid-washed jeans and your Ernest Hemingway and your object-oriented languages
and your fax machines and your hula hoops and your zoot suits and your strange
slang phrases like "That's so bogus" or "What a shocking bad hat" and those
t/data/python_quotes.txt view on Meta::CPAN
-- Paul Everitt on the term "pluggable brains", 5 Jul 1999
I picture a lump of inanimate flesh (a result from a relational database query)
being infused with the spark of life (object behavior, aka class).
-- Jim Fulton on the term "pluggable brains", 5 Jul 1999
This is good. It means that while Ionesco is dead, his spirit lives on.
-- Gordon McMillan on how Windows attaches meaning to 3-character
file extensions, 30 Jul 1999
(On the statement print "42 monkeys"+"1 snake") BTW, both Perl and Python get
this wrong. Perl gives 43 and Python gives "42 monkeys1 snake", when the answer
is clearly "41 monkeys and 1 fat snake".
-- Jim Fulton, 10 Aug 1999
I expect that what you really object to is the absence of control structures
other than goto, and the LT/GE/etc spelling of comparison operators. That was
common enough in its day, and even by the time Pascal came around the keypunch
I used still didn't have a semicolon key. It looks ugly in retrospect only
because it is <wink>.
-- Tim Peters on SNOBOL4, 17 Aug 1999
t/data/python_quotes.txt view on Meta::CPAN
The rapid establishment of social ties, even of a fleeting nature, advance not
only that goal but its standing in the uberconscious mesh of communal psychic,
subjective, and algorithmic interbeing. But I fear I'm restating the obvious.
-- Will Ware, 28 Aug 2000
The comp.lang.python newsgroup erupted last week with a flurry of posts that
accused the Python development team of creeping featurism, selling out the
language to corporate interests, moving too fast, and turning a deaf ear to the
Python community. What triggered this lava flow of accusations? The development
team accepted a proposal to change the syntax of the print statement.
-- Stephen Figgins, 30 Aug 2000
INTERVIEWER: Tell us how you came to be drawn into the world of pragmas.
COMPILER WRITER: Well, it started off with little things. Just a few
boolean flags, a way to turn asserts on and off, debug output, that sort of
thing. I thought, what harm can it do? It's not like I'm doing anything you
couldn't do with command line switches, right? Then it got a little bit
heavier, integer values for optimisation levels, even the odd string or two.
Before I knew it I was doing the real hard stuff, constant expressions,
conditionals, the whole shooting box. Then one day when I put in a hook for
t/data/www.amk.ca/quotations/python-quotes/page-2.html view on Meta::CPAN
added benefit is that John Cleese is teaching Guido how to walk
funny.
(3) Pre-Release vacations are spent in the
Catskills. Post-Release vacations are spent in the Bahamas. Guido
is currently working on a system which will allow him to make more
releases of Python; thus octupling the number of vacations he takes
in a year.</p>
<p class='source'>Matthew Lewis Carroll Smith, 4 Apr 1997</p>
<p class='quotation' id='q42'>I mean, just take a look at Joe
Strout's brilliant little "python for beginners" page. Replace all
print-statements with <code>sys.stdout.write( string.join(map(str,
args)) + "\n")</code> and you surely won't get any new beginners.
And That Would Be A Very Bad Thing.</p>
<p class='source'>Fredrik Lundh, 27 Aug 1996</p>
<p class='quotation' id='q43'>Ya, ya, ya, except ... if I were
built out of KSR chips, I'd be running at 25 or 50 MHz, and would
be wrong about ALMOST EVERYTHING almost ALL THE TIME just due to
being a computer! Think about it -- when's the last time you spent
20 hours straight debugging your
son/wife/friend/neighbor/dog/ferret/snake? And they <em>still</em>
fell over anyway? Except in a direction you've never seen before
t/data/www.amk.ca/quotations/python-quotes/page-3.html view on Meta::CPAN
<p class='quotation' id='q95'>... and at a higher conceptual level
involving graph theoretical transforms of automata (which I got
thanks to Jean Gallier by word of mouth and effort of chalk)
...</p>
<p class='source'>Aaron Watters, 17 Sep 1998</p>
<p class='quotation' id='q96'>Every clarity vanished? :-)</p>
<p class='source'>Christian Tismer, after answering a poster's
question, 17 Sep 1998</p>
<p class='quotation' id='q97'>Take the "public" modifier off
Joseph's interface, or leave it there but nest the interface inside
class "closure", or even move the interface to its own printer.java
file, and it compiles and runs without incident. Most of the big
boys I hang with aren't paralyzed by self-explanatory compiler msgs
<wink>.
not-to-mention-the-girls-ly y'rs</p>
<p class='source'>Tim Peters, 24 Sep 1998</p>
<hr /></div>
<small>[<a href="mailto:comments@amk.ca">Contact me</a>]</small>
</body>
</html>