Merge remote branch 'catalystframework/master'
Tomas Doran [Fri, 11 Dec 2009 01:42:43 +0000 (01:42 +0000)]
* catalystframework/master:
  Fix .gitignore

lib/Gitalist/Controller/Root.pm
lib/Gitalist/Utils.pm [new file with mode: 0644]

index f67e4b5..b1fd379 100644 (file)
@@ -1,11 +1,6 @@
 package Gitalist::Controller::Root;
-use Moose;
-use namespace::autoclean;
-
-BEGIN { extends 'Catalyst::Controller' }
-
-__PACKAGE__->config->{namespace} = '';
 
+use Moose;
 use Moose::Autobox;
 use Sys::Hostname ();
 use XML::Atom::Feed;
@@ -13,17 +8,15 @@ use XML::Atom::Entry;
 use XML::RSS;
 use XML::OPML::SimpleGen;
 
-=head1 NAME
-
-Gitalist::Controller::Root - Root Controller for Gitalist
+use Gitalist::Utils qw/ age_string /;
 
-=head1 DESCRIPTION
+use namespace::autoclean;
 
-[enter your description here]
+BEGIN { extends 'Catalyst::Controller' }
 
-=head1 METHODS
+__PACKAGE__->config->{namespace} = '';
 
-=cut
+sub root : Chained('/') PathPart('') CaptureArgs(0) {}
 
 sub _get_object {
   my($self, $c, $haveh) = @_;
@@ -47,13 +40,7 @@ sub _get_object {
   return $obj;
 }
 
-=head2 index
-
-Provides the project listing.
-
-=cut
-
-sub index :Path :Args(0) {
+sub index : Chained('base') PathPart('') Args(0) {
   my ( $self, $c ) = @_;
 
   $c->detach($c->req->param('a'))
@@ -78,7 +65,8 @@ sub index :Path :Args(0) {
   );
 }
 
-sub project_index : Local {
+# FIXME - WTF is this for?
+sub project_index : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
 
   my @list = @{ $c->model()->projects };
@@ -98,7 +86,7 @@ A summary of what's happening in the repo.
 
 =cut
 
-sub summary : Local {
+sub summary : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   $c->detach('error_404') unless $project;
@@ -123,7 +111,7 @@ The current list of heads (aka branches) in the repo.
 
 =cut
 
-sub heads : Local {
+sub heads : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   $c->stash(
@@ -139,7 +127,7 @@ The current list of tags in the repo.
 
 =cut
 
-sub tags : Local {
+sub tags : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   $c->stash(
@@ -149,7 +137,7 @@ sub tags : Local {
   );
 }
 
-sub blame : Local {
+sub blame : Chained('base') Args(0) {
   my($self, $c) = @_;
 
   my $project = $c->stash->{Project};
@@ -202,7 +190,7 @@ The blob action i.e the contents of a file.
 
 =cut
 
-sub blob : Local {
+sub blob : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
 
   my($blob, $head, $filename) = $self->_blob_objs($c);
@@ -225,7 +213,7 @@ The plain text version of blob, where file is rendered as is.
 
 =cut
 
-sub blob_plain : Local {
+sub blob_plain : Chained('base') Args(0) {
   my($self, $c) = @_;
 
   my($blob) = $self->_blob_objs($c);
@@ -240,7 +228,7 @@ The plain text version of blobdiff.
 
 =cut
 
-sub blobdiff_plain : Local {
+sub blobdiff_plain : Chained('base') Args(0) {
   my($self, $c) = @_;
 
   $c->stash(no_wrapper => 1);
@@ -255,7 +243,7 @@ Exposes a given diff of a blob.
 
 =cut
 
-sub blobdiff : Local {
+sub blobdiff : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $commit = $self->_get_object($c, $c->req->param('hb'));
   my $filename = $c->req->param('f')
@@ -286,7 +274,7 @@ Exposes a given commit.
 
 =cut
 
-sub commit : Local {
+sub commit : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   my $commit = $self->_get_object($c);
@@ -304,7 +292,7 @@ Exposes a given diff of a commit.
 
 =cut
 
-sub commitdiff : Local {
+sub commitdiff : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $commit = $self->_get_object($c);
   my($tree, $patch) = $c->stash->{Project}->diff(
@@ -326,7 +314,7 @@ sub commitdiff : Local {
     unless $c->stash->{no_wrapper};
 }
 
-sub commitdiff_plain : Local {
+sub commitdiff_plain : Chained('base') Args(0) {
   my($self, $c) = @_;
 
   $c->stash(no_wrapper => 1);
@@ -341,7 +329,7 @@ Expose an abbreviated log of a given sha1.
 
 =cut
 
-sub shortlog : Local {
+sub shortlog : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
 
   my $project  = $c->stash->{Project};
@@ -373,13 +361,14 @@ sub shortlog : Local {
 Calls shortlog internally. Perhaps that should be reversed ...
 
 =cut
-sub log : Local {
+
+sub log : Chained('base') Args(0) {
     $_[0]->shortlog($_[1]);
     $_[1]->stash->{action} = 'log';
 }
 
 # For legacy support.
-sub history : Local {
+sub history : Chained('base') Args(0) {
     my ( $self, $c ) = @_;
     $self->shortlog($c);
     my $project = $c->stash->{Project};
@@ -400,7 +389,7 @@ The tree of a given commit.
 
 =cut
 
-sub tree : Local {
+sub tree : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   my $commit  = $self->_get_object($c, $c->req->param('hb'));
@@ -424,7 +413,7 @@ Expose the local reflog. This may go away.
 
 =cut
 
-sub reflog : Local {
+sub reflog : Chained('base') Args(0) {
   my ( $self, $c ) = @_;
   my @log = $c->stash->{Project}->reflog(
       '--since=yesterday'
@@ -442,7 +431,7 @@ The action for the search form.
 
 =cut
 
-sub search : Local {
+sub search : Chained('base') Args(0) {
   my($self, $c) = @_;
   $c->stash(current_action => 'GitRepos');
   my $project = $c->stash->{Project};
@@ -473,7 +462,7 @@ Provides some help for the search form.
 
 =cut
 
-sub search_help : Local {
+sub search_help : Chained('base') Args(0) {
     my ($self, $c) = @_;
     $c->stash(template => 'search_help.tt2');
 }
@@ -484,7 +473,7 @@ Provides an atom feed for a given project.
 
 =cut
 
-sub atom : Local {
+sub atom : Chained('base') Args(0) {
   my($self, $c) = @_;
 
   my $feed = XML::Atom::Feed->new;
@@ -521,7 +510,7 @@ Provides an RSS feed for a given project.
 
 =cut
 
-sub rss : Local {
+sub rss : Chained('base') Args(0) {
   my ($self, $c) = @_;
 
   my $project = $c->stash->{Project};
@@ -556,7 +545,7 @@ sub rss : Local {
   $c->response->status(200);
 }
 
-sub opml : Local {
+sub opml : Chained('base') Args(0) {
   my($self, $c) = @_;
 
   my $opml = XML::OPML::SimpleGen->new();
@@ -585,7 +574,7 @@ A raw patch for a given commit.
 
 =cut
 
-sub patch : Local {
+sub patch : Chained('base') Args(0) {
     my ($self, $c) = @_;
     $c->detach('patches', [1]);
 }
@@ -596,7 +585,7 @@ The patcheset for a given commit ???
 
 =cut
 
-sub patches : Local {
+sub patches : Chained('base') Args(0) {
     my ($self, $c, $count) = @_;
     $count ||= Gitalist->config->{patches}{max};
     my $commit = $self->_get_object($c);
@@ -613,7 +602,7 @@ Provides a snapshot of a given commit.
 
 =cut
 
-sub snapshot : Local {
+sub snapshot : Chained('base') Args(0) {
     my ($self, $c) = @_;
     my $format = $c->req->param('sf') || 'tgz';
     die unless $format;
@@ -628,13 +617,8 @@ sub snapshot : Local {
     $c->response->body($snap[1]);
 }
 
-=head2 auto
-
-Populate the header and footer. Perhaps not the best location.
 
-=cut
-
-sub auto : Private {
+sub base : Chained('/root') PathPart('') CaptureArgs(0) {
   my($self, $c) = @_;
 
   my $project = $c->req->param('p');
@@ -669,12 +653,6 @@ sub auto : Private {
   );
 }
 
-=head2 end
-
-Attempt to render a view, if needed.
-
-=cut
-
 sub end : ActionClass('RenderView') {
     my ($self, $c) = @_;
     # Give project views the current HEAD.
@@ -683,50 +661,12 @@ sub end : ActionClass('RenderView') {
     }
 }
 
-sub error_404 :Private {
+sub error_404 : Action {
     my ($self, $c) = @_;
     $c->response->status(404);
     $c->response->body('Page not found');
 }
 
-sub age_string {
-  my $age = shift;
-  my $age_str;
-
-  if ( $age > 60 * 60 * 24 * 365 * 2 ) {
-    $age_str  = ( int $age / 60 / 60 / 24 / 365 );
-    $age_str .= " years ago";
-  }
-  elsif ( $age > 60 * 60 * 24 * ( 365 / 12 ) * 2 ) {
-    $age_str  = int $age / 60 / 60 / 24 / ( 365 / 12 );
-    $age_str .= " months ago";
-  }
-  elsif ( $age > 60 * 60 * 24 * 7 * 2 ) {
-    $age_str  = int $age / 60 / 60 / 24 / 7;
-    $age_str .= " weeks ago";
-  }
-  elsif ( $age > 60 * 60 * 24 * 2 ) {
-    $age_str  = int $age / 60 / 60 / 24;
-    $age_str .= " days ago";
-  }
-  elsif ( $age > 60 * 60 * 2 ) {
-    $age_str  = int $age / 60 / 60;
-    $age_str .= " hours ago";
-  }
-  elsif ( $age > 60 * 2 ) {
-    $age_str  = int $age / 60;
-    $age_str .= " min ago";
-  }
-  elsif ( $age > 2 ) {
-    $age_str  = int $age;
-    $age_str .= " sec ago";
-  }
-  else {
-    $age_str .= " right now";
-  }
-  return $age_str;
-}
-
 __PACKAGE__->meta->make_immutable;
 
 __END__
@@ -741,7 +681,21 @@ This controller handles all of the root level paths for the application
 
 =head1 METHODS
 
-=head2 age_string
+=head2 root
+
+Root of chained actions
+
+=head2 base
+
+Populate the header and footer. Perhaps not the best location.
+
+=head2 index
+
+Provides the project listing.
+
+=head2 end
+
+Attempt to render a view, if needed.
 
 =head2 blame
 
diff --git a/lib/Gitalist/Utils.pm b/lib/Gitalist/Utils.pm
new file mode 100644 (file)
index 0000000..0df4973
--- /dev/null
@@ -0,0 +1,70 @@
+package Gitalist::Utils;
+use strict;
+use warnings;
+use Exporter qw/import/;
+
+our @EXPORT_OK = qw/
+    age_string
+/;
+
+sub age_string {
+  my $age = shift;
+  my $age_str;
+
+  if ( $age > 60 * 60 * 24 * 365 * 2 ) {
+    $age_str  = ( int $age / 60 / 60 / 24 / 365 );
+    $age_str .= " years ago";
+  }
+  elsif ( $age > 60 * 60 * 24 * ( 365 / 12 ) * 2 ) {
+    $age_str  = int $age / 60 / 60 / 24 / ( 365 / 12 );
+    $age_str .= " months ago";
+  }
+  elsif ( $age > 60 * 60 * 24 * 7 * 2 ) {
+    $age_str  = int $age / 60 / 60 / 24 / 7;
+    $age_str .= " weeks ago";
+  }
+  elsif ( $age > 60 * 60 * 24 * 2 ) {
+    $age_str  = int $age / 60 / 60 / 24;
+    $age_str .= " days ago";
+  }
+  elsif ( $age > 60 * 60 * 2 ) {
+    $age_str  = int $age / 60 / 60;
+    $age_str .= " hours ago";
+  }
+  elsif ( $age > 60 * 2 ) {
+    $age_str  = int $age / 60;
+    $age_str .= " min ago";
+  }
+  elsif ( $age > 2 ) {
+    $age_str  = int $age;
+    $age_str .= " sec ago";
+  }
+  else {
+    $age_str .= " right now";
+  }
+  return $age_str;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Gitalist::Utils - trivial utils for Gitalist
+
+=head2 FUNCTIONS
+
+=head2 age_string
+
+Turns an integer number of seconds into a string..
+
+=head1 AUTHORS
+
+See L<Gitalist> for authors.
+
+=head1 LICENSE
+
+See L<Gitalist> for the license.
+
+=cut