blib/lib/Grips/Gripsrc.pm

filter: Statementstmt 16.4% 15 / 91 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 40.0% 4 / 10 Podpod 100% 5 / 5 totaltotal 11.8% 24 / 202 CC 40 SCAR 61.9
CC
40
Cov
9%
_readrc
812.0
lookup
110.0
id
6.0
CRAP 487.3
↑ Summary
1 # Grips::Gripsrc.pm
2 #
3 # Copyright (c) 2002 DIMDI <tarek.ahmed@dimdi.de>. All rights reserved.
4 #
5 # This module is free software; you can redistribute it and/or modify it under
6 # the same terms as Perl itself, i.e. under the terms of either the GNU General
7 # Public License or the Artistic License, as specified in the F<LICENCE> file.
8 package Grips::Gripsrc;
9  
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 $VERSION = "0.01"; # $Id: Gripsrc.pm,v 1.2 2003-02-04 12:19:08 ahmed Exp $
16  
17 1 my %gripsrc = ();
18  
19 sub _readrc
20 0 ▶{
Subroutine _readrc: not called CC=28 SCAR=67.0
21 0 my $host = shift;
22 0 my($home,$file);
23  
24 0 ▶ if($^O eq "MacOS") {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MacOS') { } 0 0 0
25 0 ▶ $home = $ENV{HOME} || `pwd`;
Condition0%0/3
$ENV{'HOME'} || `pwd`
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'HOME'} || `pwd`
$ENV{'HOME'} `pwd`
Truth table0%0/3
A || B
A= $ENV{'HOME'}B= `pwd`
ABresult
1X1
011
000
26 0 chomp($home);
27 0 ▶ $file = ($home =~ /:$/ ? $home . "gripsrc" : $home . ":gripsrc");
Branch: 1 branch
BranchTrueFalseTotal
$home =~ /:$/ ? : 0 0 0
28 } else {
29 # Some OS's don't have `getpwuid', so we default to $ENV{HOME}
30 0 ▶ $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
Condition0%0/3
eval { do { (getpwuid $>)[7] } } || $ENV{'HOME'}
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { (getpwuid $>)[7] } } || $ENV{'HOME'}
eval { do { (getpwuid $>)[7] } } $ENV{'HOME'}
Truth table0%0/3
A || B
A= eval { do { (getpwuid $>)[7] } }B= $ENV{'HOME'}
ABresult
1X1
011
000
31 0 $file = $home . "/.gripsrc";
32 }
33  
34 0 my $fh;
35 0 local $_;
36  
37 0 $gripsrc{default} = undef;
38  
39 # OS/2 and Win32 do not handle stat in a way compatable with this check :-(
40 0 ▶ unless($^O eq 'os2'
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O eq "os2" or $^O eq "MSWin32" or $^O eq "MacOS" or $^O =~ /^cygwin/) 0 0 0
Condition0%0/9
$^O eq "os2" or $^O eq "MSWin32" or $^O eq "MacOS" or $^O =~ /^cygwin/
l!l&&r!l&&!r
000
$^O eq "os2" or $^O eq "MSWin32" or $^O eq "MacOS"
l!l&&r!l&&!r
000
$^O eq "os2" or $^O eq "MSWin32"
l!l&&r!l&&!r
000
MC/DC0%0/4
$^O eq "os2" or $^O eq "MSWin32" or $^O eq "MacOS" or $^O =~ /^cygwin/
$^O eq "os2" $^O eq "MSWin32" $^O eq "MacOS" $^O =~ /^cygwin/
Truth table0%0/5
A or B or C or D
A= $^O eq "os2"B= $^O eq "MSWin32"C= $^O eq "MacOS"D= $^O =~ /^cygwin/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
41 || $^O eq 'MSWin32'
42 || $^O eq 'MacOS'
43 || $^O =~ /^cygwin/)
44 {
45 0 my @stat = stat($file);
46  
47 0 ▶ if(@stat)
Branch: 1 branch
BranchTrueFalseTotal
if (@stat) 0 0 0
48 {
49 0 ▶ if($stat[2] & 077)
Branch: 1 branch
BranchTrueFalseTotal
if ($stat[2] & 63) 0 0 0
50 {
51 0 carp "Bad permissions: $file";
52 0 return;
53 }
54 0 ▶ if($stat[4] != $<)
Branch: 1 branch
BranchTrueFalseTotal
if ($stat[4] != $<) 0 0 0
55 {
56 0 carp "Not owner: $file";
57 0 return;
58 }
59 }
60 }
61  
62 0 ▶ if($fh = FileHandle->new($file,"r"))
Branch: 1 branch
BranchTrueFalseTotal
if ($fh = "FileHandle"->new($file, "r")) 0 0 0
63 {
64 0 my($mach,$macdef,$tok,@tok) = (0,0);
65  
66 0 ▶ while(<$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
67 {
68 0 ▶ undef $macdef if /\A\n\Z/;
Branch: 1 branch
BranchTrueFalseTotal
if /\A\n\Z/ 0 0 0
69  
70 0 ▶ if($macdef)
Branch: 1 branch
BranchTrueFalseTotal
if ($macdef) 0 0 0
71 {
72 0 push(@$macdef,$_);
73 0 next;
74 }
75  
76 0 s/^\s*//;
77 0 chomp;
78 0 ▶ push(@tok, $+)
Branch: 1 branch
BranchTrueFalseTotal
length $_ and s/^("([^"]*)"|(\S+))\s*// and do { push @tok, $+ } 0 0 0
Condition0%0/3
length $_ and s/^("([^"]*)"|(\S+))\s*//
!ll&&!rl&&r
000
MC/DC0%0/2
length $_ and s/^("([^"]*)"|(\S+))\s*//
length $_ s/^("([^"]*)"|(\S+))\s*//
Truth table0%0/3
A and B
A= length $_B= s/^("([^"]*)"|(\S+))\s*//
ABresult
0X0
100
111
79 while(length && s/^("([^"]*)"|(\S+))\s*//);
80  
81 TOKEN:
82 0 ▶ while(@tok)
Branch: 1 branch
BranchTrueFalseTotal
if (@tok) 0 0 0
83 {
84 0 ▶ if($tok[0] eq "default")
Branch: 1 branch
BranchTrueFalseTotal
if ($tok[0] eq "default") 0 0 0
85 {
86 0 shift(@tok);
87 0 $mach = bless {};
88 0 $gripsrc{default} = [$mach];
89  
90 0 next TOKEN;
91 }
92  
93 last TOKEN
94 0 ▶ unless @tok > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @tok > 1 0 0 0
95  
96 0 $tok = shift(@tok);
97  
98 0 ▶ if($tok eq "host")
Branch: 3 branches
BranchTrueFalseTotal
if ($tok eq 'host') { } 0 0 0
elsif ($tok =~ /^(id|user|pwd)$/) { } 0 0 0
elsif ($tok eq 'macdef') { } 0 0 0
99 {
100 0 my $host = shift @tok;
101 0 $mach = bless {host => $host};
102  
103 $gripsrc{$host} = []
104 0 ▶ unless exists($gripsrc{$host});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $gripsrc{$host} 0 0 0
105 0 push(@{$gripsrc{$host}}, $mach);
106 }
107 elsif($tok =~ /^(id|user|pwd)$/)
108 {
109 0 ▶ next TOKEN unless $mach;
Branch: 1 branch
BranchTrueFalseTotal
unless $mach 0 0 0
110 0 my $value = shift @tok;
111 # Following line added by rmerrell to remove '/' escape char in .gripsrc
112 0 $value =~ s/\/\\/\\/g;
113 0 $mach->{$1} = $value;
114 }
115 elsif($tok eq "macdef")
116 {
117 0 ▶ next TOKEN unless $mach;
Branch: 1 branch
BranchTrueFalseTotal
unless $mach 0 0 0
118 0 my $value = shift @tok;
119 $mach->{macdef} = {}
120 0 ▶ unless exists $mach->{macdef};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mach->{"macdef"} 0 0 0
121 0 $macdef = $mach->{machdef}{$value} = [];
122 }
123 }
124 }
125 0 $fh->close();
126 }
127 }
128  
129 sub lookup
130 0 ▶{
Subroutine lookup: not called CC=10 SCAR=47.0
Pod documented
131 0 my($pkg,$mach,$id) = @_;
132  
133 _readrc()
134 0 ▶ unless exists $gripsrc{default};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $gripsrc{"default"} 0 0 0
135  
136 0 ▶ $mach ||= 'default';
Condition0%0/2
$mach ||= "default"
l!l
00
MC/DC0%0/1
$mach ||= "default"
$mach
Truth table0%0/2
A
A= $mach
Aresult
11
00
137 0 ▶ undef $id
Branch: 1 branch
BranchTrueFalseTotal
if $mach eq "default" 0 0 0
138 if $mach eq 'default';
139  
140 0 ▶ if(exists $gripsrc{$mach})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $gripsrc{$mach}) 0 0 0
141 {
142 0 ▶ if(defined $id)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 0 0 0
143 {
144 0 my $m;
145 0 foreach $m (@{$gripsrc{$mach}})
146 {
147 return $m
148 0 ▶ if(exists $m->{id} && $m->{id} eq $id);
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"id"} and $m->{"id"} eq $id 0 0 0
Condition0%0/3
exists $m->{"id"} and $m->{"id"} eq $id
!ll&&!rl&&r
000
MC/DC0%0/2
exists $m->{"id"} and $m->{"id"} eq $id
exists $m->{"id"} $m->{"id"} eq $id
Truth table0%0/3
A and B
A= exists $m->{"id"}B= $m->{"id"} eq $id
ABresult
0X0
100
111
149 }
150 0 return undef;
151 }
152 0 return $gripsrc{$mach}->[0]
153 }
154  
155 return $gripsrc{default}->[0]
156 0 ▶ if defined $gripsrc{default};
Branch: 1 branch
BranchTrueFalseTotal
if defined $gripsrc{"default"} 0 0 0
157  
158 0 return undef;
159 }
160  
161 sub id
162 0 ▶{
Subroutine id: not called CC=2 SCAR=17.9
Pod documented
163 0 my $me = shift;
164  
165 exists $me->{id}
166 ? $me->{id}
167 0 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $me->{'id'} ? : 0 0 0
168 }
169  
170 sub pwd
171 0 ▶{
Subroutine pwd: not called CC=2 SCAR=17.9
Pod documented
172 0 my $me = shift;
173  
174 exists $me->{pwd}
175 ? $me->{pwd}
176 0 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $me->{'pwd'} ? : 0 0 0
177 }
178  
179 sub user
180 0 ▶{
Subroutine user: not called CC=2 SCAR=17.9
Pod documented
181 0 my $me = shift;
182  
183 exists $me->{user}
184 ? $me->{user}
185 0 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $me->{'user'} ? : 0 0 0
186 }
187  
188 sub iup
189 0 ▶{
Subroutine iup: not called CC=1 SCAR=6.9
Pod documented
190 0 my $me = shift;
191 0 ($me->id, $me->user, $me->pwd);
192 }
193  
194 1 1;
195  
196 __END__
↑ Summary