/[Frey]/trunk/lib/Frey/DBIC/Browser.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/DBIC/Browser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1014 - (show annotations)
Sun Jan 25 12:57:28 2009 UTC (15 years, 3 months ago) by dpavlin
File size: 1299 byte(s)
DBIC refactor of Reblog into sponge
1 package Frey::DBIC::Browser;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6 with 'Frey::Config';
7 #with 'Frey::Storage';
8
9 has dbic_class => (
10 is => 'rw',
11 isa => 'Str',
12 requried => 1,
13 default => 'Reblog',
14 );
15
16 has dsn => (
17 is => 'rw',
18 isa => 'Str',
19 required => 1,
20 default => 'DBI:mysql:database=reblog;host=127.0.0.1;port=13306',
21 );
22
23 has page => (
24 is => 'rw',
25 isa => 'Int',
26 required => 1,
27 default => 1,
28 );
29
30 sub as_sponge {
31 my ($self) = @_;
32
33 my $dbic_class = $self->dbic_class;
34 my $dsn = $self->dsn;
35 my $schema;
36
37 my $code = qq{
38 use $dbic_class ;
39 \$schema = $dbic_class->connect("$dsn", '', '');
40 };
41
42 eval $code;
43 die $@ if $@;
44
45 warn "# schema ", $self->dump( $schema );
46
47 my @feeds = $schema->resultset('Feeds')->search(
48 undef,
49 {
50 page => $self->page,
51 order_by => [ 'timestamp desc' ],
52 }
53 );
54
55 my @rows;
56 my @name;
57 my $name_pos;
58
59 foreach my $feed ( @feeds ) {
60 my %row = $feed->get_columns;
61
62 my @row;
63
64 foreach my $name ( $feed->columns ) {
65 if ( ! defined $name_pos->{$name} ) {
66 push @name, $name;
67 $name_pos->{$name} = $#name;
68 warn "## name_pos: ", $self->dump( $name_pos ) if $self->debug;
69 }
70
71 my $pos = $name_pos->{$name};
72 $row[$pos] = $row{$name};
73 }
74
75 push @rows, [ @row ];
76 }
77
78 return {
79 rows => \@rows,
80 NAME => \@name,
81 }
82 }
83
84 1;

  ViewVC Help
Powered by ViewVC 1.1.26