ACME-QuoteDB

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

my $builder = $class->new(
    module_name         => 'ACME::QuoteDB',
    license             => 'perl',
    dist_author         => 'David Wright <david_v_wright@yahoo.com>',
    dist_version_from   => 'lib/ACME/QuoteDB.pm',
    build_requires => {
        #'Module::Build'    => '0.33',
        'Module::Build'    => '0.280801',
        'Test::More'       => 0.8,
        'Readonly'         => 1.03,
        'Data::Dumper'     => 2.121,
        'Carp'             => 1.04,
        #'criticism'        => 1.02,
        'version'          => 0.70,
        'aliased'          => 0.22,
        'File::Basename'   => 2.74,
        'DBD::SQLite'      => 1.14,
        'Class::DBI'       => '3.0.17',
        'HTML::TokeParser' => 2.37,
        'Text::CSV'        => 1.06, #1.10, # 1.13
        'Cwd'              => 3.25, #3.29

META.yml  view on Meta::CPAN

  - 'David Wright <david_v_wright@yahoo.com>'
abstract: 'API implements CRUD for a Collection of Quotes (adages/proverbs/sayings/epigrams, etc)'
license: perl
resources:
  license: http://dev.perl.org/licenses/
build_requires:
  Carp: 1.04
  Class::DBI: 3.0.17
  Cwd: 3.25
  DBD::SQLite: 1.14
  Data::Dumper: 2.121
  File::Basename: 2.74
  File::Copy: 2.11
  File::Spec: 3.2501
  HTML::TokeParser: 2.37
  Module::Build: 0.280801
  Readonly: 1.03
  Test::More: 0.8
  Text::CSV: 1.06
  aliased: 0.22
  version: 0.7

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


#major-version.minor-revision.bugfix
use version; our $VERSION = qv('0.1.2');

#use criticism 'brutal'; # use critic with a ~/.perlcriticrc

use Exporter 'import';
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 {

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

The only supported databases at this time are sqlite and mysql.

It is trivial to add support for others

=back

=head1 DEPENDENCIES

L<Carp>

L<Data::Dumper>

L<criticism> (pragma - enforce Perl::Critic if installed)

L<version>(pragma - version numbers)

L<aliased>

L<Test::More>

L<DBD::SQLite>

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

BEGIN {local $ENV{PERL_TEXT_CSV} = 0}

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';
use aliased 'ACME::QuoteDB::DB::DBI'     => 'QDBI';
use File::Basename qw/dirname basename/;
use File::Glob qw(:globally :nocase);
use Encode qw/is_utf8 decode/;
use Data::Dumper qw/Dumper/;
use Carp qw/carp croak/;
use Text::CSV;
use Readonly;
use DBI;

# if not in utf8 latin1 is assumed
my $FILE_ENCODING = 'iso-8859-1';

Readonly my @QUOTE_FIELDS => qw/quote name source catg rating/;

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

ways to represt the data. (same with 'custom')
(see tests for examples - there is a test for loading a 'fortune' file format)

One can subclass ACME::QuoteDB::LoadDB and override dbload,
to do our html parsing

=head2 debug_record

dump record (show what is set on the internal data structure) 

e.g. Data::Dumper

=head2 set_record

only needed it one plans to sub-class this module.
otherwise, is transparent in usage.

if you are sub-classing this module, you would have to populate 
this record. (L</write_record> knows about/uses this data structure)

possible fields consist of:

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

see: L<LOADING QUOTES|ACME::QuoteDB/LOADING QUOTES>


=back 


=head1 DEPENDENCIES

L<Carp>

L<Data::Dumper>

L<criticism> (pragma - enforce Perl::Critic if installed)

L<version>(pragma - version numbers)

L<aliased>

L<Test::More>

L<DBD::SQLite>

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

    eval "use DBD::SQLite";
    $@ and croak 'DBD::SQLite is a required dependancy';
}

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

#use Test::More 'no_plan';
use Test::More tests => 29;
use File::Basename qw/dirname/;
use Data::Dumper qw/Dumper/;
use File::Spec;

# A. test dry run, show if parsing is succesful but don't load the database
{
  my $q = File::Spec->catfile((dirname(__FILE__),'data'), 
                               'simpsons_quotes.tsv.csv'
          );

  # only 2 supported formats: 'simple' text (which is the default) and 'tsv' 
  my $load_db = ACME::QuoteDB::LoadDB->new({

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

}

{ # load from html is not supported because there are too many 
  # ways to represt the data.
  # this is an example of extracting quotes from html:
  # subclass ACME::QuoteDB::LoadDB and override dbload,
  # to do our html parsing
  package LoadQuoteDBFromHtml;
  use base 'ACME::QuoteDB::LoadDB';
  use Carp qw/croak/;
  use Data::Dumper qw/Dumper/;
  use HTML::TokeParser;

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

      my $p = HTML::TokeParser->new($file) || croak $!;
    
      while (my $token = $p->get_tag("p")) {
          my $idn = $token->[1]{class} || q{};
          my $id = $token->[1]{id} || q{}; # if a quotation is continued (id

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

  
  is( $sq->list_attr_names, join "\n", sort @expected_attribution_list);
}

{ # prove load a fortune format file
  # 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{};

t/02-get_quotes.t  view on Meta::CPAN


use strict;
use warnings;

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

#use Test::More 'no_plan';
use Test::More tests => 33;
use File::Basename qw/dirname/;
use Data::Dumper qw/Dumper/;
use Carp qw/croak/;
use File::Spec;


BEGIN {
    eval "use DBD::SQLite";
    $@ and croak 'DBD::SQLite is a required dependancy';
}

#make test db writeable

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


use strict;
use warnings;

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

#use Test::More 'no_plan';
use Test::More tests => 24;
use File::Basename qw/dirname/;
use Data::Dumper qw/Dumper/;
use Carp qw/croak/;
use File::Spec;
use Readonly;

BEGIN {
    eval "use DBD::SQLite";
    $@ and croak 'DBD::SQLite is a required dependancy';
}


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

use strict;
use warnings;
use utf8; # yes this source code does contain utf8 characters

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

#use Test::More 'no_plan';
use Test::More tests => 8;
use File::Basename qw/dirname/;
use Data::Dumper qw/Dumper/;
use Carp qw/croak/;
use File::Temp;
use File::Spec;


BEGIN {
    eval "use DBD::SQLite";
    $@ and croak 'DBD::SQLite is a required dependancy';

    # give alternate path to the DB



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