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;
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) = @_;
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'))
);
}
-sub project_index : Local {
+# FIXME - WTF is this for?
+sub project_index : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my @list = @{ $c->model()->projects };
=cut
-sub summary : Local {
+sub summary : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my $project = $c->stash->{Project};
$c->detach('error_404') unless $project;
=cut
-sub heads : Local {
+sub heads : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my $project = $c->stash->{Project};
$c->stash(
=cut
-sub tags : Local {
+sub tags : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my $project = $c->stash->{Project};
$c->stash(
);
}
-sub blame : Local {
+sub blame : Chained('base') Args(0) {
my($self, $c) = @_;
my $project = $c->stash->{Project};
=cut
-sub blob : Local {
+sub blob : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my($blob, $head, $filename) = $self->_blob_objs($c);
=cut
-sub blob_plain : Local {
+sub blob_plain : Chained('base') Args(0) {
my($self, $c) = @_;
my($blob) = $self->_blob_objs($c);
=cut
-sub blobdiff_plain : Local {
+sub blobdiff_plain : Chained('base') Args(0) {
my($self, $c) = @_;
$c->stash(no_wrapper => 1);
=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')
=cut
-sub commit : Local {
+sub commit : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my $project = $c->stash->{Project};
my $commit = $self->_get_object($c);
=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(
unless $c->stash->{no_wrapper};
}
-sub commitdiff_plain : Local {
+sub commitdiff_plain : Chained('base') Args(0) {
my($self, $c) = @_;
$c->stash(no_wrapper => 1);
=cut
-sub shortlog : Local {
+sub shortlog : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my $project = $c->stash->{Project};
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};
=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'));
=cut
-sub reflog : Local {
+sub reflog : Chained('base') Args(0) {
my ( $self, $c ) = @_;
my @log = $c->stash->{Project}->reflog(
'--since=yesterday'
=cut
-sub search : Local {
+sub search : Chained('base') Args(0) {
my($self, $c) = @_;
$c->stash(current_action => 'GitRepos');
my $project = $c->stash->{Project};
=cut
-sub search_help : Local {
+sub search_help : Chained('base') Args(0) {
my ($self, $c) = @_;
$c->stash(template => 'search_help.tt2');
}
=cut
-sub atom : Local {
+sub atom : Chained('base') Args(0) {
my($self, $c) = @_;
my $feed = XML::Atom::Feed->new;
=cut
-sub rss : Local {
+sub rss : Chained('base') Args(0) {
my ($self, $c) = @_;
my $project = $c->stash->{Project};
$c->response->status(200);
}
-sub opml : Local {
+sub opml : Chained('base') Args(0) {
my($self, $c) = @_;
my $opml = XML::OPML::SimpleGen->new();
=cut
-sub patch : Local {
+sub patch : Chained('base') Args(0) {
my ($self, $c) = @_;
$c->detach('patches', [1]);
}
=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);
=cut
-sub snapshot : Local {
+sub snapshot : Chained('base') Args(0) {
my ($self, $c) = @_;
my $format = $c->req->param('sf') || 'tgz';
die unless $format;
$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');
);
}
-=head2 end
-
-Attempt to render a view, if needed.
-
-=cut
-
sub end : ActionClass('RenderView') {
my ($self, $c) = @_;
# Give project views the current HEAD.
}
}
-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__
=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
--- /dev/null
+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