ACME-QuoteDB

 view release on metacpan or  search on metacpan

lib/ACME/QuoteDB.pm  view on Meta::CPAN

our @EXPORT = qw/quote/; # support one liner

use Carp qw/croak/;
use Data::Dumper qw/Dumper/;
use ACME::QuoteDB::LoadDB;
use aliased 'ACME::QuoteDB::DB::Attribution' => 'Attr';
use aliased 'ACME::QuoteDB::DB::QuoteCatg'  => 'QuoteCatg';
use aliased 'ACME::QuoteDB::DB::Category'  => 'Catg';
use aliased 'ACME::QuoteDB::DB::Quote'    => 'Quote';

binmode STDOUT, ':encoding(utf8)';
binmode STDERR, ':encoding(utf8)';

sub new {
    my $class = shift;
    my $self = bless {}, $class;
    return $self;
}

# provide 1 non OO method for one liners
sub quote {
    my ($arg_ref) = @_;

lib/ACME/QuoteDB/LoadDB.pm  view on Meta::CPAN

    $self->{record}->{quote}  = q{};
    $self->{record}->{rating} = q{};
    $self->{record}->{name}   = q{};
    $self->{record}->{source} = q{};
    $self->{record}->{catg}   = q{};

    $self->{file}        = $args->{file};
    $self->{dir}         = $args->{dir};
    $self->{data}        = $args->{data};
    $self->{file_format} = $args->{file_format};
    $FILE_ENCODING       = $args->{file_encoding} || $FILE_ENCODING;
    $self->{delim}       = $args->{delimiter};
    $self->{verbose}     = $args->{verbose};
    $self->{category}    = $args->{category};
    $self->{rating}      = $args->{rating};
    $self->{attr_source} = $args->{attr_source};
    $self->{orig_args}   = $args;
    $self->{success}     = undef;

    # start with if set
    $self->{record}->{rating} = $self->{rating};

lib/ACME/QuoteDB/LoadDB.pm  view on Meta::CPAN

sub dbload_from_csv {
  my ($self, $file) = @_;

  my $delim = $self->{delim} || ',';
  my $csv = Text::CSV->new({
     sep_char => $delim,
     binary => 1
  });
  $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",

lib/ACME/QuoteDB/LoadDB.pm  view on Meta::CPAN


TODO one quote to multiple categories

=item  attr_source - extracted from data if exists, otherwise will use what you
specify

example:

{attr_source => 'The Simpsons'}

=item  file_encoding - optional

Files being loaded are assumed to be utf8 encoded. if utf8 flag is not detected,
falls back to latin1 (iso-8859-1). If neither of these is correct, set this
option to the encoding your file is in.

=back

=head4 Operation Related Parameters

=over 4

=item  dry_run - optional

do not write to the database. Use with verbose flag to see what would have beed

t/01-load_quotes.t  view on Meta::CPAN

  # this is an example of importing a file in the 'fortune' format
  # subclass ACME::QuoteDB::LoadDB and override dbload, to do our parsing
  package Fortune2QuoteDB;
  use base 'ACME::QuoteDB::LoadDB';
  use Carp qw/croak/;
  use Data::Dumper qw/Dumper/;

  sub dbload {
    my ($self, $file) = @_;

    open my $source, '<:encoding(utf8)', $file || croak $!;

    local $/ = $self->{delim};

    my $q = q{};

    while (my $line = <$source>){

      #$self->debug_record;

      $q .= $line;

t/04-load_get_quote_utf8.t  view on Meta::CPAN

#!perl -T
# /* vim:et: set ts=4 sw=4 sts=4 tw=78 encoding=utf-8: */

use 5.008005;        # require perl 5.8.5
                     # DBD::SQLite Unicode is not supported before 5.8.5
use strict;
use warnings;
use utf8; # yes this source code does contain utf8 characters

use ACME::QuoteDB;
use ACME::QuoteDB::LoadDB;

t/data/python_quotes.txt  view on Meta::CPAN

      -- Barry Warsaw, 23 Mar 2000

    >Have you ever looked at the output of a bib | tbl | eqn pipeline?
    Are you kids still using that as a pick-up line?
      -- Roy Smith and Cameron Laird, 4 Apr 2000

This is like getting lost in a dictionary. What does quincuncial mean anyhow?
      -- Dennis Hamilton, 4 Apr 2000

UTF-8 has a certain purity in that it equally annoys every nation, and is
nobody's default encoding.
      -- Andy Robinson, 10 Apr 2000

    "Now if we could figure out where python programmers are from, someone
could write a book and get rich."
    "Yorkshire."
      -- Quinn Dunkan and Warren Postma, 11 Apr 2000

If I didn't have my part-time performance art income to help pay the bills, I
could never afford to support my programming lifestyle.
      -- Jeff Bauer, 21 Apr 2000

t/data/www.amk.ca/quotations/python-quotes/index.html  view on Meta::CPAN

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://www.amk.ca/foaf/author">
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
<link rel="stylesheet" href="/base.css" type="text/css" />
<meta name="ICBM" content="38.87510,-77.28705" />
<meta name="geo.position" content="38.87510; -77.28705" />
<meta name="DC.title" content="Python Quotes, page 1 of 10" />

t/data/www.amk.ca/quotations/python-quotes/page-10.html  view on Meta::CPAN

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://www.amk.ca/foaf/author">
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
<link rel="stylesheet" href="/base.css" type="text/css" />
<meta name="ICBM" content="38.87510,-77.28705" />
<meta name="geo.position" content="38.87510; -77.28705" />
<meta name="DC.title" content="Python Quotes, page 10 of 10" />

t/data/www.amk.ca/quotations/python-quotes/page-2.html  view on Meta::CPAN

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://www.amk.ca/foaf/author">
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
<link rel="stylesheet" href="/base.css" type="text/css" />
<meta name="ICBM" content="38.87510,-77.28705" />
<meta name="geo.position" content="38.87510; -77.28705" />
<meta name="DC.title" content="Python Quotes, page 2 of 10" />

t/data/www.amk.ca/quotations/python-quotes/page-3.html  view on Meta::CPAN

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://www.amk.ca/foaf/author">
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 1 September 2005), see www.w3.org" />
<link rel="stylesheet" href="/base.css" type="text/css" />
<meta name="ICBM" content="38.87510,-77.28705" />
<meta name="geo.position" content="38.87510; -77.28705" />
<meta name="DC.title" content="Python Quotes, page 3 of 10" />



( run in 0.858 second using v1.01-cache-2.11-cpan-a5abf4f5562 )