blib/lib/SVN/ACL.pm

filter: Statementstmt 59.4% 44 / 74 Branchbran 45.4% 10 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 10 totaltotal 54.2% 64 / 118 CC 16 SCAR 31.6
CC
16
Cov
56%
export
72.0
grant
6.2
new
3.1
CRAP 23.5
↑ Summary
1 package SVN::ACL;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.02';
7  
8 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod undocumented
9 1 my $class = shift;
10 1 my $path = shift;
11 1 my $perm;
12
13 1 my $aclfile = "$path/YAML.conf";
14 1 ▶ (-w $path) or die "Can't access the config file: $aclfile";
Branch: 1 branch
BranchTrueFalseTotal
-w $path or die "Can't access the config file: $aclfile" 1 0 1
15 1 ▶ if (-e $aclfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $aclfile) { } 0 1 1
16 0 $perm = YAML::LoadFile($aclfile);
17 }
18 else {
19 1 $perm->{dir}->{'/'}->{'*'} = 'r';
20  
21 }
22 1 bless ( { path => $path,
23 perm => $perm }, $class );
24 }
25  
26 0 ▶sub newdir {
Subroutine newdir: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my $self = shift;
28 0 my $dir = shift;
29 0 $self->{perm}->{dir}->{$dir}->{'*'} = '';
30 }
31  
32 1 ▶sub newuser {
Subroutine newuser: called CC=1 SCAR=0.0
Pod undocumented
33 1 my $self = shift;
34 1 my ($name, $password) = @_;
35 1 $self->{perm}->{user}->{$name} = $password;
36 }
37  
38 1 ▶sub deluser {
Subroutine deluser: called CC=1 SCAR=0.0
Pod undocumented
39 1 my $self = shift;
40 1 my $name = shift;
41 1 delete $self->{perm}->{user}->{$name};
42 }
43  
44 1 ▶sub newgroup {
Subroutine newgroup: called CC=1 SCAR=0.0
Pod undocumented
45 1 my $self = shift;
46 1 my $group = shift;
47 1 $self->{perm}->{group}->{"@".$group} = [];
48 }
49  
50 1 ▶sub delgroup {
Subroutine delgroup: called CC=1 SCAR=0.0
Pod undocumented
51 1 my $self = shift;
52 1 my $group = shift;
53 1 delete $self->{perm}->{group}->{"@".$group};
54 }
55  
56 3 ▶sub grant {
Subroutine grant: called CC=6 SCAR=18.2
Pod undocumented
57 3 my $self = shift;
58 3 my ($dir, $user, $permission) = @_;
59 3 ▶ if ($user =~ /^@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user =~ /^@/) { } 1 2 3
60 1 ▶ exists ($self->{perm}->{group}->{$user})
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"perm"}{"group"}{$user} or die "no such group, you have to new the user first" 1 0 1
61 or die "no such group, you have to new the user first";
62 $permission ? $self->{perm}->{dir}->{$dir}->{$user} = $permission
63 1 ▶ : delete $self->{perm}->{dir}->{$dir}->{$user};
Branch: 1 branch
BranchTrueFalseTotal
$permission ? : 1 0 1
64 }
65 else {
66 # $self->newdir($dir) unless (exists $self->{perm}->{dir}->{$dir});
67 2 ▶ exists ($self->{perm}->{user}->{$user})
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"perm"}{"user"}{$user} or die "no such user, you have to new the user first" 2 0 2
68 or die "no such user, you have to new the user first";
69 $permission ? $self->{perm}->{dir}->{$dir}->{$user} = $permission
70 2 ▶ : delete $self->{perm}->{dir}->{$dir}->{$user};
Branch: 1 branch
BranchTrueFalseTotal
$permission ? : 1 1 2
71 }
72 }
73  
74 1 ▶sub togroup {
Subroutine togroup: called CC=2 SCAR=7.0
Pod undocumented
75 1 my $self = shift;
76 1 my ($user, $group) = @_;
77 1 $group = "@".$group;
78 1 ▶ $self->{perm}->{group}->{$group} = [] unless (exists $self->{perm}->{group}->{$group});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"perm"}{"group"}{$group} 0 1 1
79 1 push @{$self->{perm}->{group}->{$group}}, $user;
80 }
81  
82 0 ▶sub export {
Subroutine export: not called CC=8 SCAR=42.8
Pod undocumented
83 0 my $self = shift;
84 0 my $repospath = $self->{path};
85 # parse the svnserv.conf
86 0 ▶ open SVNSERV, ">$repospath/conf/svnserve.conf" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open SVNSERV, ">$repospath/conf/svnserve.conf" or die $! 0 0 0
87 0 print SVNSERV << "CONF";
88 [general]
89 anon-access = read
90 auth-access = write
91 password-db = passwd
92 authz-db = authz
93 CONF
94 0 close SVNSERV;
95 # parse passwd file
96 0 ▶ open PASSWD, ">$repospath/conf/passwd" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open PASSWD, ">$repospath/conf/passwd" or die $! 0 0 0
97 0 print PASSWD "[users]\n";
98 0 print PASSWD "$_ = ".$self->{perm}->{user}->{$_}."\n" for keys %{$self->{perm}->{user}};
99 0 close PASSWD;
100 # parse authz
101 0 ▶ open AUTHZ, ">$repospath/conf/authz" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open AUTHZ, ">$repospath/conf/authz" or die $! 0 0 0
102 0 print AUTHZ "[groups]\n";
103 0 for (keys %{$self->{perm}->{group}}) {
104 0 my $users = join ",", @{$self->{perm}->{group}->{$_}};
105 0 print AUTHZ "$_ = $users\n"
106 }
107 0 print AUTHZ "\n\n";
108 0 for my $path (keys %{$self->{perm}->{dir}}) {
109 0 print AUTHZ "[$path]\n";
110 0 for (keys %{$self->{perm}->{dir}->{$path}}) {
111 0 print AUTHZ "$_ = ".$self->{perm}->{dir}->{$path}->{$_}."\n";
112 }
113 0 print AUTHZ "\n";
114 }
115 0 close AUTHZ;
116 }
117  
118 1 ▶sub save {
Subroutine save: called CC=1 SCAR=0.0
Pod undocumented
119 1 my $self = shift;
120 1 my $aclfile = $self->{path}."/YAML.conf";
121 1 YAML::DumpFile($aclfile, $self->{perm});
122 }
123  
124 1 1;
125  
126 __END__
↑ Summary