Permalink
Browse files

wip

  • Loading branch information...
1 parent de73b38 commit 3a9a9ec2eb20c17415c38eb3dd270f926c20e669 @yanick committed Dec 14, 2010
Showing with 136 additions and 0 deletions.
  1. +51 −0 lib/Galuga/Controller/Widget.pm
  2. +85 −0 lib/Galuga/Widget/CPANModules.pm
@@ -0,0 +1,51 @@
+package Galuga::Controller::Widget;
+use Moose;
+use namespace::autoclean;
+
+BEGIN {extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+Galuga::Controller::Widget - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index
+
+=cut
+
+sub index :Path :Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->response->body('Matched Galuga::Controller::Widget in Widget.');
+}
+
+sub foo :Local :Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->res->body( "tourlou" );
+
+}
+
+
+=head1 AUTHOR
+
+Yanick Champoux,,,
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
@@ -0,0 +1,85 @@
+package Galuga::Widget::CPANModules;
+
+use 5.10.0;
+
+use strict;
+use warnings;
+
+use Template::Declare::Tags;
+use base 'Template::Declare';
+
+use LWP::Simple;
+use pQuery;
+use DateTime::Format::Flexible;
+
+template widget => sub {
+ my $self = shift;
+ my %arg = @_;
+ my $c = $arg{c};
+
+ div {
+ attr { class => 'widget cpan_modules' };
+ h3 { 'CPAN Modules' };
+
+ show( 'module', %$_ ) for get_modules();
+ }
+
+};
+
+template 'module' => sub {
+ my ( $self, %arg ) = @_;
+
+ div {
+ div {
+ a { href is $arg{url}; $arg{name} };
+ };
+ div {
+ $arg{version};
+ };
+ div { $arg{date}->strftime( '%b %e, %Y' ) };
+ }
+
+};
+
+sub get_modules {
+state $page = get "http://search.cpan.org/~yanick";
+
+my $dists = pQuery( $page )->find('table:eq(1) tr');
+
+my @dists;
+
+$dists->each(sub{
+ return unless shift; # first one is headers
+
+ my $row = pQuery($_);
+ my $name = $row->find('td:eq(0) a')->text();
+
+ $name =~ s/-v?([\d._]*)$//; # remove version
+
+ my $version = $1;
+
+ my $url = "http://search.cpan.org/dist/$name";
+
+ $name =~ s/-/::/g;
+
+ my $desc = $row->find('td:eq(1)')->text();
+ my $date = DateTime::Format::Flexible->parse_datetime(
+ $row->find('td:eq(3)')->text );
+
+ push @dists, {
+ name => $name,
+ url => $url,
+ desc => $desc,
+ date => $date,
+ version => $version,
+ };
+});
+
+return @dists = reverse sort { $a->{date} cmp $b->{date} } @dists;
+
+}
+
+
+1;
+
+

0 comments on commit 3a9a9ec

Please sign in to comment.