Created
October 14, 2010 18:39
-
-
Save sharifulin/626753 to your computer and use it in GitHub Desktop.
Mojolicious app + dw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controller | |
sub list { | |
my $self = shift; | |
my $DB = $self->app->db; | |
my $where = $self->stash('act') ? 'status=' . $DB->quote( $self->stash('act') ) : 1; | |
$self->stash( | |
page => $_, | |
list => $_->{start} | |
? $DB->dw::feedback($DB->select( | |
"select * from feedback where $where order by -id " . $DB->limit($_->{start}-1, $_->{limit}) | |
)) | |
: [] | |
) for Util::page( | |
$DB->select("select count(*) cnt from feedback where $where")->[0]->{cnt}, | |
$self->app->conf->{limit}->{wall} => $self->req->param('page') | |
); | |
} | |
# dw | |
package dw; | |
use strict; | |
use Data::Lazy::BUD::SLICELY; | |
use Data::Stuff; | |
{ | |
no strict 'refs'; | |
for my $x ( | |
qw(user user_like user_comment feedback), | |
) { | |
*{"dw::g::$x"} = sub { my $DB = shift; my $f = shift; my $m = "dw::$x"; | |
GROUP {$_->{$f}} $DB->$m($DB->select("select * from $x where ".$f.$DB->in(@$_))) | |
}; | |
} | |
} | |
sub feedback { my $DB = shift; | |
SLICELY { CHV {$_->[0]} $DB->dw::g::user('id') } 'user_id' => 'user' => | |
SLICELY { $DB->dw::g::user_like ('feedback_id') } 'id' => 'like_list' => | |
SLICELY { $DB->dw::g::user_comment('feedback_id') } 'id' => 'comment' => | |
SLICELY { CHV { | |
my $h; $h->{ $_->{user_id} } = $_ for @$_; $h | |
} $DB->dw::g::user_like('feedback_id') } 'id' => 'like' => | |
$_[0]; | |
} | |
sub user_like { my $DB = shift; | |
SLICELY { CHV {$_->[0]} $DB->dw::g::user ('id') } 'user_id' => 'user' => | |
SLICELY { CHV {$_->[0]} $DB->dw::g::feedback('id') } 'feedback_id' => 'feedback' => | |
$_[0]; | |
} | |
sub user_comment { ... } | |
sub user { ... } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment