Created
September 30, 2008 04:22
-
-
Save beppu/13740 to your computer and use it in GitHub Desktop.
This file contains 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
package App; | |
use base 'Squatting'; | |
use Coro::AnyEvent; ### <<< --- very important XXX XXX XXX | |
our %CONFIG = ( | |
host => 'http://localhost:5984/', | |
db => 'app', | |
); | |
package App::Controllers; | |
use Squatting ':controllers'; | |
use Data::Dump 'pp'; | |
*all_links = \&App::Models::all_links; | |
our @C = ( | |
C( | |
Main => ['/list'], | |
get => sub { | |
my ($self) = @_; | |
my $cr = $self->cr; | |
my $v = $self->v; | |
$v->{links} = all_links(); | |
#$self->log->info( pp $v->{links}); | |
$self->render('main'); | |
} | |
), | |
C( | |
Index => ['/'], | |
get => sub { | |
my ($self) = @_; | |
$self->redirect( R('Main') ); | |
} | |
) | |
); | |
1; | |
package App::Models; | |
use strict; | |
use warnings; | |
use AnyEvent::CouchDB; | |
use Clone 'clone'; | |
our $DB; | |
sub db { | |
$DB || do { | |
my $couch = couch($App::CONFIG{host}); | |
my $DB = $couch->db($App::CONFIG{db}); | |
eval { $DB->info->recv; }; | |
if ($@) { | |
#$DB->create->recv; | |
#$DB->save_doc($DESIGN_PAGES)->recv; | |
} | |
$DB; | |
}; | |
} | |
our $maps = { | |
'all_links' => sub { | |
my $arg = shift; | |
qq|function(doc){ emit(null, doc); }|; | |
} | |
}; | |
sub all_links { | |
my $db = db; | |
#my $results = $db->view('pages/recent', { descending => "true" })->recv; | |
my $results = $db->query($maps->{all_links}->(), '', '', { count => 100 })->recv; | |
my @links = map { $_->{value} } @{ $results->{rows} }; | |
return \@links; | |
} | |
1; | |
package App::Views; | |
use strict; | |
use warnings; | |
use CGI ':standard'; | |
use Squatting ':views'; | |
use Data::Dump 'pp'; | |
our @V = ( | |
V( | |
'html', | |
layout => sub { | |
my ($self, $v, @body) = @_; | |
join "", | |
start_html( | |
-title => "Example", | |
-head => style($self->_css) | |
), | |
div({ -id => 'header' }, h1('Links')), | |
div({ -id => 'content' }, @body), | |
end_html; | |
}, | |
_css => sub { | |
qq| | |
body { | |
background:#000 none repeat scroll 0 0; | |
font-size:100.1%; | |
margin:0; padding:0; | |
} | |
input, label, h1, h2, h3, h4, h5, li, dt, a, p, b, span { | |
font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; | |
color: #eee; | |
} | |
|; | |
}, | |
main => sub { | |
my ($self, $v) = @_; | |
h2("leobm"), ul( | |
join( | |
'', | |
map { | |
#my $item =$_->{value}; | |
my $link = $_; | |
li( | |
h3($link->{title}), | |
h4($link->{description}), | |
div(map { a({ href => '#', class => 'tag' }, $_->{name}) } @{ $link->{tags} }) | |
); | |
} @{ $v->{links} } | |
) | |
); | |
} | |
) | |
); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment