[Dbix-class] Re: using as normal perl module

Adam Sjøgren asjo at koldfront.dk
Fri Jul 29 20:41:52 GMT 2011


On Thu, 28 Jul 2011 14:52:35 -0700 (PDT), Rajeev wrote:

> all the examples i see are of using the module in a webapp (built with
> catalyst). I am only trying to use it in my cgi perl programe, but
> finding very less documentation. can someone please refer a URL or
> small script which stores and retrieves data from a table using this
> module plz.

I recently used DBIx::Class in a very simple command-line script that
reads files from the filesystem and stuffs them into the database.

I looked roughly like this:

  #!/usr/bin/perl

  use strict;
  use warnings;
  use utf8;
  use File::Slurp qw(slurp);

  use MessageID::DB;

  my $schema=MessageID::DB->connect('dbi:Pg:dbname=message-id', 'USER', 'PASSWD', { AutoCommit=>1, pg_enable_utf8=>1 });

  my $transaction=sub {
      while(my $filename=<>) {
          chomp $filename;
          my $article=slurp($filename);
          my $message_id=extract_message_id($article, $filename);
          $schema->resultset('Article')->create({ message_id=>$message_id, article=>$article });
      }
  };

  $schema->txn_do($transaction);

It is trivial, but you asked for something that doesn't use Catalyst and
is small (I left out the helper-sub and the error-checking) :-)

Maybe if you show what you have tried and describe what you wanted, it
is easier to get help.


  Best regards,

    Adam

-- 
 "Good car to drive after a war"                              Adam Sjøgren
                                                         asjo at koldfront.dk



More information about the DBIx-Class mailing list