blib/lib/SVN/Web/Checkout.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/SVN/Web/Browse.pm ↑ Summary blib/lib/SVN/Web/Diff.pm »
1 package SVN::Web::Checkout;
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 use SVN::Web::X;
10  
11 our $VERSION = 0.62;
12  
13 =head1 NAME
14  
15 SVN::Web::Checkout - SVN::Web action to checkout a given file
16  
17 =head1 SYNOPSIS
18  
19 In F<config.yaml>
20  
21 actions:
22 ...
23 checkout:
24 class: SVN::Web::Checkout
25 action_menu:
26 show:
27 - file
28 link_text: (checkout)
29 ...
30  
31 =head1 DESCRIPTION
32  
33 Returns the contents of the given filename. Uses the C<svn:mime-type>
34 property.
35  
36 =head1 OPTIONS
37  
38 =over 4
39  
40 =item rev
41  
42 The repository revision to checkout. Defaults to the repository's youngest
43 revision.
44  
45 =back
46  
47 =head1 TEMPLATE VARIABLES
48  
49 N/A
50  
51 =head1 EXCEPTIONS
52  
53 =over 4
54  
55 =item (path %1 is not a file in revision %2)
56  
57 The given path is not a file in the given revision.
58  
59 =back
60  
61 =cut
62  
63 sub run {
64 my $self = shift;
65 my $ra = $self->{repos}{ra};
66 my $rev = $self->{cgi}->param('rev') || $ra->get_latest_revnum();
67  
68 my $uri = $self->{repos}{uri};
69 $uri .= '/'.$self->rpath if $self->rpath;
70  
71 my $node_kind = $self->svn_get_node_kind($uri, $rev, $rev);
72  
73 if ( $node_kind != $SVN::Node::file ) {
74 SVN::Web::X->throw(
75 error => '(path %1 is not a file in revision %2)',
76 vars => [ $self->rpath, $rev ]
77 );
78 }
79  
80 my ( $fh, $fc ) = ( undef, '' );
81 open( $fh, '>', \$fc );
82 $self->ctx_cat( $fh, $uri, $rev );
83 close($fh);
84  
85 my $mime_type;
86 my $props = $self->ctx_propget( 'svn:mime-type', $uri, $rev, 0 );
87 if ( exists $props->{$uri} ) {
88 $mime_type = $props->{$uri};
89 }
90 else {
91 $mime_type = 'text/plain';
92 }
93  
94 return {
95 mimetype => $mime_type,
96 body => $fc,
97 };
98 }
99  
100 1;
101  
102 =head1 COPYRIGHT
103  
104 Copyright 2003-2004 by Chia-liang Kao C<< <clkao@clkao.org> >>.
105  
106 Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>.
107  
108 This program is free software; you can redistribute it and/or modify it
109 under the same terms as Perl itself.
110  
111 See L<http://www.perl.com/perl/misc/Artistic.html>
112  
113 =cut
« blib/lib/SVN/Web/Browse.pm ↑ Summary blib/lib/SVN/Web/Diff.pm »