| 1 | package SVN::Web::View; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use base 'SVN::Web::action'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | use Encode (); | ||
| 9 | |||
| 10 | our $VERSION = 0.62; | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | SVN::Web::View - SVN::Web action to view a file in the repository | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | In F<config.yaml> | ||
| 19 | |||
| 20 | actions: | ||
| 21 | ... | ||
| 22 | view: | ||
| 23 | class: SVN::Web::View | ||
| 24 | action_menu: | ||
| 25 | show: | ||
| 26 | - file | ||
| 27 | link_text: (view file) | ||
| 28 | ... | ||
| 29 | |||
| 30 | =head1 DESCRIPTION | ||
| 31 | |||
| 32 | Shows a specific revision of a file in the Subversion repository. Includes | ||
| 33 | the commit information for that file. | ||
| 34 | |||
| 35 | =head1 OPTIONS | ||
| 36 | |||
| 37 | =over 8 | ||
| 38 | |||
| 39 | =item rev | ||
| 40 | |||
| 41 | The revision of the file to show. Defaults to the repository's | ||
| 42 | youngest revision. | ||
| 43 | |||
| 44 | If this is not an interesting revision for this file, the repository history | ||
| 45 | is searched to find the youngest interesting revision for this file that is | ||
| 46 | less than C<rev>. | ||
| 47 | |||
| 48 | =back | ||
| 49 | |||
| 50 | =head1 TEMPLATE VARIABLES | ||
| 51 | |||
| 52 | =over 8 | ||
| 53 | |||
| 54 | =item at_head | ||
| 55 | |||
| 56 | A boolean value, indicating whether the user is currently viewing the | ||
| 57 | HEAD of the file in the repository. | ||
| 58 | |||
| 59 | =item context | ||
| 60 | |||
| 61 | Always C<file>. | ||
| 62 | |||
| 63 | =item rev | ||
| 64 | |||
| 65 | The revision that has been returned. This is not necessarily the same | ||
| 66 | as the C<rev> option passed to the action. If the C<rev> passed to the | ||
| 67 | action is not interesting (i.e., there were no changes to the file at that | ||
| 68 | revision) then the file's history is searched backwards to find the next | ||
| 69 | oldest interesting revision. | ||
| 70 | |||
| 71 | =item youngest_rev | ||
| 72 | |||
| 73 | The youngest interesting revision of the file. | ||
| 74 | |||
| 75 | =item mimetype | ||
| 76 | |||
| 77 | The file's MIME type, extracted from the file's C<svn:mime-type> | ||
| 78 | property. If this is not set then C<text/plain> is used. | ||
| 79 | |||
| 80 | =item file | ||
| 81 | |||
| 82 | The contents of the file. | ||
| 83 | |||
| 84 | =item author | ||
| 85 | |||
| 86 | The revision's author. | ||
| 87 | |||
| 88 | =item date | ||
| 89 | |||
| 90 | The date the revision was committed, formatted according to | ||
| 91 | L<SVN::Web/"Time and date formatting">. | ||
| 92 | |||
| 93 | =item msg | ||
| 94 | |||
| 95 | The revision's commit message. | ||
| 96 | |||
| 97 | =back | ||
| 98 | |||
| 99 | =head1 EXCEPTIONS | ||
| 100 | |||
| 101 | None. | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | sub _log { | ||
| 106 | my ( $self, $paths, $rev, $author, $date, $msg, $pool ) = @_; | ||
| 107 | |||
| 108 | return unless $rev > 0; | ||
| 109 | |||
| 110 | return { | ||
| 111 | rev => $rev, | ||
| 112 | author => $author, | ||
| 113 | date => $self->format_svn_timestamp($date), | ||
| 114 | msg => Encode::decode('utf8',$msg), | ||
| 115 | }; | ||
| 116 | } | ||
| 117 | |||
| 118 | sub cache_key { | ||
| 119 | my $self = shift; | ||
| 120 | my $path = $self->{path}; | ||
| 121 | |||
| 122 | my ( undef, undef, $act_rev, $head ) = $self->get_revs(); | ||
| 123 | |||
| 124 | return "$act_rev:$head:$path"; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub run { | ||
| 128 | my $self = shift; | ||
| 129 | my $ra = $self->{repos}{ra}; | ||
| 130 | |||
| 131 | my $uri = $self->{repos}{uri}; | ||
| 132 | $uri .= '/'.$self->rpath if $self->rpath; | ||
| 133 | |||
| 134 | my ( $exp_rev, $yng_rev, $act_rev, $head ) = $self->get_revs(); | ||
| 135 | |||
| 136 | my $rev = $act_rev; | ||
| 137 | |||
| 138 | # Get the log for this revision of the file | ||
| 139 | $ra->get_log( [ $self->rpath ], $rev, $rev, 1, 1, 1, sub { $self->{REV} = $self->_log(@_) } ); | ||
| 140 | |||
| 141 | # Get the text for this revision of the file | ||
| 142 | my ( $fh, $fc ) = ( undef, '' ); | ||
| 143 | open( $fh, '>', \$fc ); | ||
| 144 | $self->ctx_cat( $fh, $uri, $rev ); | ||
| 145 | close($fc); | ||
| 146 | $fc = Encode::decode('utf8', $fc); | ||
| 147 | |||
| 148 | my $mime_type; | ||
| 149 | my $props = $self->ctx_propget( 'svn:mime-type', $uri, $rev, 0 ); | ||
| 150 | if ( exists $props->{$uri} ) { | ||
| 151 | $mime_type = $props->{$uri}; | ||
| 152 | } | ||
| 153 | else { | ||
| 154 | $mime_type = 'text/plain'; | ||
| 155 | } | ||
| 156 | |||
| 157 | return { | ||
| 158 | template => 'view', | ||
| 159 | data => { | ||
| 160 | context => 'file', | ||
| 161 | rev => $act_rev, | ||
| 162 | youngest_rev => $yng_rev, | ||
| 163 | at_head => $head, | ||
| 164 | mimetype => $mime_type, | ||
| 165 | file => $fc, | ||
| 166 | %{ $self->{REV} }, | ||
| 167 | } | ||
| 168 | }; | ||
| 169 | } | ||
| 170 | |||
| 171 | 1; | ||
| 172 | |||
| 173 | =head1 COPYRIGHT | ||
| 174 | |||
| 175 | Copyright 2003-2004 by Chia-liang Kao C<< <clkao@clkao.org> >>. | ||
| 176 | |||
| 177 | Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>. | ||
| 178 | |||
| 179 | This program is free software; you can redistribute it and/or modify it | ||
| 180 | under the same terms as Perl itself. | ||
| 181 | |||
| 182 | See L<http://www.perl.com/perl/misc/Artistic.html> | ||
| 183 | |||
| 184 | =cut | ||