/[Frey]/trunk/lib/Frey/DBI.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/Frey/DBI.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 455 - (hide annotations)
Wed Nov 19 15:28:23 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 681 byte(s)
rename invocable events with prefix as_ with fallback in Frey::Web

This started with brute-force rename using:

  perl -p -i -n -e 's/sub markup/sub as_markup/'  `grep -lr 'sub markup' lib t`
  perl -p -i -n -e 's/sub data/sub as_data/'      `grep -lr 'sub data' lib t`
  perl -p -i -n -e 's/sub sponge/sub as_sponge/'  `grep -lr 'sub sponge' lib t`

  perl -p -i -n -e 's/->markup/->as_markup/'      `grep -lr -- '->markup' lib t`
  perl -p -i -n -e 's/->data/->as_data/'          `grep -lr -- '->data' lib t`
  perl -p -i -n -e 's/->sponge/->as_sponge/'      `grep -lr -- '->sponge' lib t`

  perl -p -i -n -e 's!/markup!/as_markup!'        `grep -lr -- '/markup' lib t etc`
  perl -p -i -n -e 's!/data!/as_data!'            `grep -lr -- '/data' lib t etc`
  perl -p -i -n -e 's!/sponge!/as_sponge!'        `grep -lr -- '/sponge' lib t etc`

1 dpavlin 366 package Frey::DBI;
2     use Moose;
3    
4     extends 'Frey';
5    
6     use DBI;
7     use Moose::Util::TypeConstraints;
8    
9     subtype 'dsn'
10     => as 'Str'
11     => where {
12     DBI->parse_dsn( $_ );
13     };
14    
15     has 'dsn' => (
16     is => 'ro',
17     isa => 'dsn',
18     default => 'DBI:Pg:dbname=template1',
19     required => 1,
20     );
21    
22     has 'query' => (
23     is => 'ro',
24     isa => 'Str',
25     required => 1,
26     default => 'select 42 as meaning_of_life',
27     );
28    
29 dpavlin 455 sub as_sponge {
30 dpavlin 366 my ( $self ) = @_;
31    
32     my $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;
33     $dbh->do( qq{ set client_encoding='utf-8' } );
34    
35     my $sth = $dbh->prepare( $self->query );
36     $sth->execute();
37    
38     return {
39     NAME => $sth->{NAME},
40     rows => $sth->fetchall_arrayref,
41     };
42     }
43    
44     1;

  ViewVC Help
Powered by ViewVC 1.1.26