blib/lib/MYDan/Code/SVN.pm untested

filter: Statementstmt 0.0% 0 / 82 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 177 CC 19 SCAR 39.5
CC
19
Cov
0%
searchUser
110.0
getUsers
20.0
new
12.0
CRAP 51.7
1 package MYDan::Code::SVN;
2 use strict;
3 use warnings;
4  
5 $|++;
6  
7 sub new
8 {
9 my ( $class, %self ) = splice @_;
10 map{ die "$_ undef" unless $self{$_} }qw( name path );
11 die "path no array" unless ref $self{path} eq 'ARRAY';
12 bless \%self, ref $class || $class;
13 }
14  
15 sub searchUser
16 {
17 my ( $this, $user ) = @_;
18  
19 unless( $user && $user =~ /^[a-zA-Z0-9\._\-]+@[a-zA-Z0-9\.]+$/ && $user !~ /^block__/ )
20 {
21 warn "user name format not support.\n";
22 return;
23 }
24  
25  
26 my ( $i, $type ) = ( 0, '' );
27 for my $path ( map{ glob $_ }@{$this->{path}} )
28 {
29 my @conf = `cat '$path'`;
30 map{ $_ =~ s/[\r]*\n$// }@conf;
31  
32 $type = '';
33 my @group;
34 for my $conf ( @conf )
35 {
36 $conf =~ s/#.*//;
37  
38 if( $conf =~ /^\s*\[/ ) { $type = $conf; next; }
39  
40 next unless $conf =~ /$user/;
41  
42 if( $conf =~ /^$user\s*=\s*/ )
43 {
44 printf "[%i]: $user $this->{name} project $path $type $conf\n", ++$i;
45 }
46 elsif( $conf =~ /,$user\b/ || $conf =~ /=\s*$user\b/ )
47 {
48 if( $conf =~ /^(.*)=/ )
49 {
50 printf "[%i]: $user $this->{name} group $path $type $1\n", ++$i;
51 push @group, $1;
52 }
53 }
54 }
55  
56 $type = '';
57 for my $group ( @group )
58 {
59 for my $conf ( @conf )
60 {
61 $conf =~ s/#.*//;
62  
63 if( $conf =~ /^\[/ ) { $type = $conf; next; }
64  
65 next unless $conf =~ /$group/;
66  
67 if( $conf =~ /^\@$group\s*=\s*/ )
68 {
69 printf "[%i]: $group $this->{name} bygroup $path $type $conf\n", ++$i;
70 }
71 }
72 }
73 }
74 }
75  
76 sub getUsers
77 {
78 my ( $this, %email )= shift;
79  
80 for my $path ( map{ glob $_ }@{$this->{path}} )
81 {
82 my @conf = `cat '$path'`;
83  
84 my ( $i, %print ) = ( 0 );
85  
86 for my $conf ( @conf )
87 {
88 $conf =~ s/#.*//;
89 next unless my @g = $conf =~ /([a-zA-Z0-9\.\-_]+@[a-z]+\.[a-z]+)/g;
90 map{
91 my $p;
92 if( $_ =~ /^block__(.+)$/ )
93 {
94 $p = "$this->{name} $path $1 block";
95 }
96 else
97 {
98 $p = "$this->{name} $path $_ active";
99 $email{$_} ++;
100 }
101  
102 printf "[%i] $p\n", ++$i unless $print{$p};
103 $print{$p} ++;
104 }@g;
105 }
106 }
107 return %email;
108 }
109  
110 sub blockUser
111 {
112 my ( $this, $user ) = @_;
113  
114 unless( $user && $user =~ /^[a-zA-Z0-9\._\-]+@[a-zA-Z0-9\.]+$/ && $user !~ /^block__/ )
115 {
116 warn "user name format not support.\n";
117 return;
118 }
119  
120 return if ! $user || ! @{$this->{path}};
121  
122 my $path = join ' ', @{$this->{path}};
123 system "sed -i 's/\\([=, ]\\)$user/\\1block__$user/g;s/^$user/block__$user/' $path";
124 }
125  
126 sub unblockUser
127 {
128 my ( $this, $user ) = @_;
129  
130 unless( $user && $user =~ /^[a-zA-Z0-9\._\-]+@[a-zA-Z0-9\.]+$/ && $user !~ /^block__/ )
131 {
132 warn "user name format not support.\n";
133 return;
134 }
135  
136 return if ! $user || ! @{$this->{path}};
137  
138 my $path = join ' ', @{$this->{path}};
139 system "sed -i 's/\\([=, ]\\)block__$user/\\1$user/g;s/^block__$user/$user/' $path";
140 }
141  
142 1;