/[Frey]/trunk/lib/Frey/SQL.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

Contents of /trunk/lib/Frey/SQL.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 455 - (show annotations)
Wed Nov 19 15:28:23 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 942 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 package Frey::SQL;
2 use Moose;
3 extends 'Frey';
4
5 with 'Frey::Web';
6
7 use MooseX::Types::Moose qw(Str Int ArrayRef);
8 use MooseX::Types::Structured qw/Dict/;
9
10 use DBI;
11 use Data::Dump qw/dump/;
12
13 has 'query' => (
14 is => 'rw',
15 isa => 'Str',
16 required => 1,
17 default => 'select * from sponge',
18 documentation => 'SQL query to filter data',
19 );
20
21 has table => (
22 is => 'rw',
23 isa => 'Str',
24 required => 1,
25 default => 'sponge',
26 documentation => 'Name of table to create from sponge data',
27 );
28
29 has 'sponge' => (
30 is => 'rw',
31 isa => Dict[
32 rows => ArrayRef[ArrayRef],
33 NAME => ArrayRef[Str],
34 ],
35 required => 1,
36 );
37
38 sub as_data {
39 my ($self) = @_;
40
41 my $dbh=DBI->connect('dbi:AnyData(RaiseError=>1):');
42
43 my $data = $self->as_sponge->{rows};
44 unshift @$data, $self->as_sponge->{NAME};
45
46 warn "# data = ",dump( $data ) if $self->debug;
47
48 $dbh->func( $self->table, 'ARRAY', $data, 'ad_import' );
49
50 return $dbh->selectall_arrayref( $self->query );
51 }
52
53 1;

  ViewVC Help
Powered by ViewVC 1.1.26