blib/lib/SVN/Web/List.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/Diff.pm ↑ Summary blib/lib/SVN/Web/Log.pm »
1 package SVN::Web::List;
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 File::Basename ();
9  
10 our $VERSION = 0.54;
11  
12 =head1 NAME
13  
14 SVN::Web::List - SVN::Web action to list available repositories
15  
16 =head1 SYNOPSIS
17  
18 In F<config.yaml>
19  
20 actions:
21 ...
22 list:
23 class: SVN::Web::List
24 opts:
25 redirect_to_browse_when_one_repo: 0 # or 1
26 public_repos_uri: hide_local
27 ...
28  
29 =head1 DESCRIPTION
30  
31 Displays a list of available Subversion repositories for browsing. If only
32 one repo is available then may redirect straight to it.
33  
34 =head1 CONFIGURATION
35  
36 The following options may be specified in F<config.yaml>
37  
38 =over
39  
40 =item redirect_to_browse_when_one_repo
41  
42 Boolean indicating whether, if only one repository is available, SVN::Web::List
43 should immediately issue a redirect to browse that repository, thereby saving
44 the user a mouse click.
45  
46 Defaults to 0.
47  
48 =item public_repos_uri
49  
50 Can be 'hide_local', which will hide the URL for any file:// repositories,
51 'hide_all', which will hide all repositories, or a hash. The hash should be
52 keyed by the repository name, and the values should be either a URL display, or
53 a false value to hide the URL.
54  
55 The default is to show all repository URLs.
56  
57 =back
58  
59 =head1 TEMPLATE VARIABLES
60  
61 =over 8
62  
63 =item reposcount
64  
65 The number of repositories that were configured.
66  
67 =item repos
68  
69 A hash. Keys are repository names, paths are repository URLs.
70  
71 =back
72  
73 =head1 EXCEPTIONS
74  
75 None.
76  
77 =cut
78  
79 my %default_opts = ( redirect_to_browse_when_one_repo => 0 );
80  
81 sub run {
82 my $self = shift;
83  
84 $self->{opts} = { %default_opts, %{ $self->{opts} } };
85  
86 my %repos = repos_list( $self->{config} );
87  
88 # If there's only one repo listed then jump straight to it
89 if ( keys %repos == 1 and $self->{opts}{redirect_to_browse_when_one_repo} )
90 {
91 my $url = $self->{cgi}->self_url();
92 $url =~ s{/$}{};
93 $url .= '/' . ( keys %repos )[0];
94 print $self->{cgi}->redirect( -uri => $url );
95 return;
96 }
97  
98 my $public_repos = $self->{opts}{public_repos_uri} || '';
99 if (lc $public_repos eq 'hide_all') {
100 for my $rep (values %repos) {
101 undef $rep;
102 }
103 }
104 elsif (lc $public_repos eq 'hide_local') {
105 for my $rep (values %repos) {
106 if ($rep =~ m{file://}) {
107 undef $rep;
108 }
109 }
110 }
111 elsif (ref $public_repos eq 'HASH') {
112 for my $repname (keys %repos) {
113 if (exists $public_repos->{$repname}) {
114 $repos{$repname} = $public_repos->{$repname};
115 }
116 }
117 }
118  
119 return {
120 template => 'list',
121 data => {
122 action => 'list',
123 nonav => 1,
124 repos => \%repos,
125 reposcount => scalar keys %repos
126 }
127 };
128 }
129  
130 sub repos_list {
131 my $config = shift;
132  
133 my %repos;
134 if ( $config->{reposparent} ) {
135 opendir my $dh, "$config->{reposparent}"
136 or SVN::Web::X->throw(
137 error => '(opendir reposparent %1 %2)',
138 vars => [ $config->{reposparent}, $! ]
139 );
140  
141 for my $dir (
142 grep {
143 -d File::Spec->catdir( $config->{reposparent}, $_ )
144 && !/^\./
145 } readdir $dh
146 )
147 {
148 $repos{$dir} =
149 'file://' . File::Spec->catdir( $config->{reposparent}, $dir );
150 }
151 }
152 else {
153  
154 %repos = %{ $config->{repos} };
155 }
156  
157 delete @repos{ @{ $config->{block} } } if exists $config->{block};
158  
159 return %repos;
160 }
161  
162 1;
163  
164 =head1 COPYRIGHT
165  
166 Copyright 2003-2004 by Chia-liang Kao C<< <clkao@clkao.org> >>.
167  
168 Copyright 2005-2007 by Nik Clayton C<< <nik@FreeBSD.org> >>.
169  
170 Copyright 2012 by Dean Hamstead C<< <dean@fragfest.com.au> >>.
171  
172 This program is free software; you can redistribute it and/or modify it
173 under the same terms as Perl itself.
174  
175 See L<http://www.perl.com/perl/misc/Artistic.html>
176  
177 =cut
« blib/lib/SVN/Web/Diff.pm ↑ Summary blib/lib/SVN/Web/Log.pm »