Skip to content
Browse files

Added CPANTS rating

  • Loading branch information...
1 parent 8a08bb9 commit c9b672483fd5335f710ea91a9fe4f81707306380 @vti committed
Showing with 70 additions and 12 deletions.
  1. +5 −4 Makefile.PL
  2. +7 −2 config.yml
  3. +9 −4 lib/Perlresume.pm
  4. +40 −0 lib/Perlresume/Kwalitee.pm
  5. +1 −1 views/layouts/main.caml
  6. +8 −1 views/resume.caml
View
9 Makefile.PL
@@ -12,10 +12,11 @@ WriteMakefile(
: ()),
PL_FILES => {},
PREREQ_PM => {
- 'Test::More' => 0,
- 'YAML' => 0,
- 'Dancer' => 1.3030,
- 'MetaCPAN::API' => 0
+ 'Test::More' => 0,
+ 'YAML' => 0,
+ 'Dancer' => 1.3030,
+ 'Dancer::Plugin::Database' => 0,
+ 'MetaCPAN::API' => 0
},
dist => {COMPRESS => 'gzip -9f', SUFFIX => 'gz',},
clean => {FILES => 'Perlresume-*'},
View
9 config.yml
@@ -8,5 +8,10 @@ template: "caml"
plugins:
Database:
- driver: 'SQLite'
- database: 'perlresume.db'
+ connections:
+ perlresume:
+ driver: 'SQLite'
+ database: 'perlresume.db'
+ cpants:
+ driver: 'SQLite'
+ database: 'cpants_all.db'
View
13 lib/Perlresume.pm
@@ -2,10 +2,12 @@ package Perlresume;
use Dancer ':syntax';
use Dancer::Plugin::Database;
use Perlresume::MetaCPAN;
+use Perlresume::Kwalitee;
our $VERSION = '0.1';
my $mcpan = Perlresume::MetaCPAN->new;
+my $kwalitee = Perlresume::Kwalitee->new(dbh => database('cpants'));
get '/' => sub {
if (my $author = params->{author}) {
@@ -33,11 +35,14 @@ get '/:author' => sub {
my $views = $author->{views};
update_author($author);
+ my $kwalitee_profile = $kwalitee->fetch_author($id);
+
template 'resume' => {
title => $cpan_profile->{asciiname}
? $cpan_profile->{asciiname}
: $cpan_profile->{name},
%$cpan_profile,
+ kwalitee => $kwalitee_profile,
views => $author->{views}
};
};
@@ -48,14 +53,14 @@ sub find_or_create {
my ($author) = @_;
if (my $author =
- database->quick_select('resume', {pauseid => $author->{pauseid}}))
+ database('perlresume')->quick_select('resume', {pauseid => $author->{pauseid}}))
{
return $author;
}
my $name = $author->{asciiname} ? $author->{asciiname} : $author->{name};
- database->quick_insert('resume',
+ database('perlresume')->quick_insert('resume',
{pauseid => $author->{pauseid}, name => $name, updated => time});
return {pauseid => $author->{pauseid}, views => 0};
@@ -64,12 +69,12 @@ sub find_or_create {
sub update_author {
my ($author) = @_;
- database->quick_update('resume', {pauseid => $author->{pauseid}},
+ database('perlresume')->quick_update('resume', {pauseid => $author->{pauseid}},
$author);
}
sub load_last_searches {
- my $sth = database->prepare(
+ my $sth = database('perlresume')->prepare(
'SELECT pauseid, name FROM resume ORDER BY updated DESC LIMIT 10',
);
$sth->execute;
View
40 lib/Perlresume/Kwalitee.pm
@@ -0,0 +1,40 @@
+package Perlresume::Kwalitee;
+
+use strict;
+use warnings;
+
+sub new {
+ my $class = shift;
+
+ my $self = bless {@_}, $class;
+
+ return $self;
+}
+
+sub fetch_author {
+ my $self = shift;
+ my ($pauseid) = @_;
+
+ my $dbh = $self->{dbh};
+
+ my $sth = $dbh->prepare(<<'');
+SELECT
+ average_kwalitee,
+ rank,
+ average_total_kwalitee
+FROM `author`
+WHERE `pauseid` = ?
+
+ $sth->execute($pauseid);
+
+ my $result = $sth->fetchall_arrayref;
+
+ return {} unless $result && @$result;
+
+ return {
+ average_kwalitee => $result->[0]->[0],
+ rank => $result->[0]->[1]
+ };
+}
+
+1;
View
2 views/layouts/main.caml
@@ -19,7 +19,7 @@
{{&content}}
</div>
<div id="footer">
- Written by <a href="http://showmetheco.de">vti</a> | Powered by <a href="http://perldancer.org/">Dancer</a> and <a href="http://metacpan.org">MetaCPAN</a>
+ Written by <a href="http://showmetheco.de">vti</a> | Powered by <a href="http://perldancer.org/">Dancer</a>, <a href="http://metacpan.org">MetaCPAN</a> and <a href="http://cpants.perl.org">CPANTS</a>
</div>
</div>
<script type="text/javascript">
View
9 views/resume.caml
@@ -40,7 +40,7 @@
<td class="desription">
I am a yet another proud Perl programmer {{#city}}based in
{{city}}{{/city}} with <a
- href="http://metacpan.org/author/{{pauseid}}">{{dist_count}}</a>
+ href="http://metacpan.org/author/{{pauseid}}">{{dist_count}}</a>
distributions currently on CPAN{{#first_release_year}} since
{{first_release_year}}{{/first_release_year}}.
@@ -60,6 +60,13 @@
<td class="description">
My CPAN modules are used by {{dists_users_count}} other distributions{{#favorited_dist_count}} and
were favorited {{favorited_dist_count}} times{{/favorited_dist_count}}.
+
+ {{#kwalitee}}I am
+ #<a
+ href="http://cpants.charsbar.org/author/{{pauseid}}">{{rank}}</a>
+ in CPANTS rating ({{average_kwalitee}}%&nbsp;average
+ kwalitee).{{/kwalitee}}
+
{{#has_github_account}}
<br /><br />
On GitHub I have <a href="http://github.com/{{id}}/followers"><span

0 comments on commit c9b6724

Please sign in to comment.
Something went wrong with that request. Please try again.