lib/App/teai/Config.pm

filter: Statementstmt 94.0% 126 / 134 Branchbran 83.7% 77 / 92 Conditioncond 62.0% 54 / 87 MC/DCmcdc 49.0% 25 / 51 Subroutinesub 91.6% 22 / 24 Podpod 100% 12 / 12 totaltotal 79.0% 316 / 400 CC 82 SCAR 26.6
CC
82
Cov
82%
state_dir
42.0
host
30.0
load
25.0
CRAP 14.4
« lib/App/teai/Lead.pm ↑ Summary lib/App/teai/Lock.pm »
1 package App::teai::Config;
2 41 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use Errno qw(EISDIR);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 41 ▶use Fcntl qw(:flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 41 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 41 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 41 ▶use App::teai::Err;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 41 ▶use App::teai::Wire qw(valid_id);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 41 our $VERSION = '0.08';
12  
13 41 my @AGENTS = qw(claude codex agy muse kimi grok shell);
14 41 my %KEYS = map { $_ => 1 } qw(url user password creds tls_ca);
15 41 my %ENVKEY = (url => 'TEAI_URL', user => 'TEAI_USER', password => 'TEAI_PASSWORD',
16 creds => 'TEAI_CREDS', tls_ca => 'TEAI_TLS_CA');
17  
18 151 ▶sub _env ($n) { my $x = $ENV{$n}; defined $x && length $x ? $x : undef }
Subroutine _env: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $x && length $x ? : 41 110 151
Condition100%3/3
defined $x and length $x
!ll&&!rl&&r
101941
MC/DC100%2/2
defined $x and length $x
defined $x length $x
Truth table100%3/3
A and B
A= defined $xB= length $x
ABresult
0X0
100
111
19  
20 27 ▶sub _config_path () {
Subroutine _config_path: called CC=7 SCAR=20.2
21 27 ▶ if (defined(my $p = _env('TEAI_CONFIG'))) { return ($p, 1) }
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $p = _env("TEAI_CONFIG"))) 21 6 27
22 6 my $x = _env('XDG_CONFIG_HOME');
23 6 ▶ return ("$x/teai/config", 0) if defined $x && $x =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if defined $x and $x =~ m[\A/]u 1 5 6
Condition100%3/3
defined $x and $x =~ m[\A/]u
!ll&&!rl&&r
411
MC/DC100%2/2
defined $x and $x =~ m[\A/]u
defined $x $x =~ m[\A/]u
Truth table100%3/3
A and B
A= defined $xB= $x =~ m[\A/]u
ABresult
0X0
100
111
24 5 ▶ my $home = _env('HOME') // (getpwuid $<)[7];
Condition33%1/3
_env("HOME") // (getpwuid $<)[7]
l!l&&r!l&&!r
500
MC/DC0%0/2
_env("HOME") // (getpwuid $<)[7]
_env("HOME") (getpwuid $<)[7]
Truth table33%1/3
A // B
A= _env("HOME")B= (getpwuid $<)[7]
ABresult
1X1
011
000
25 5 ▶ return (undef, 0) unless defined $home && length $home;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $home and length $home 0 5 5
Condition33%1/3
defined $home and length $home
!ll&&!rl&&r
005
MC/DC0%0/2
defined $home and length $home
defined $home length $home
Truth table33%1/3
A and B
A= defined $homeB= length $home
ABresult
0X0
100
111
26 5 return ("$home/.config/teai/config", 0);
27 }
28  
29 41 my %warned;
30  
31 27 ▶sub load () {
Subroutine load: called CC=25 SCAR=32.2
Pod documented
32 27 my ($file, $explicit) = _config_path();
33 27 my %v;
34 27 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 27 0 27
35 27 my $ok = open(my $fh, '<', $file);
36 27 ▶ if ($ok && -d $fh) { $ok = 0; $! = EISDIR }
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and -d $fh) 2 25 27
Condition100%3/3
$ok and -d $fh
!ll&&!rl&&r
6192
MC/DC100%2/2
$ok and -d $fh
$ok -d $fh
Truth table100%3/3
A and B
A= $okB= -d $fh
ABresult
0X0
100
111
37 27 ▶ if ($ok) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ok) { } 19 8 27
elsif ($explicit) { } 3 5 8
elsif (not $!{'ENOENT'} || $!{'ENOTDIR'}) { } 2 3 5
38 19 ▶ if (-f $fh && ((stat _)[2] & 044) && !$warned{$file}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $fh and (stat _)[2] & 36 and not $warned{$file}++) 2 17 19
Condition83%5/6
-f $fh and (stat _)[2] & 36 and not $warned{$file}++
!ll&&!rl&&r
1702
-f $fh and (stat _)[2] & 36
!ll&&!rl&&r
1162
MC/DC66%2/3
-f $fh and (stat _)[2] & 36 and not $warned{$file}++
-f $fh (stat _)[2] & 36 not $warned{$file}++
Truth table75%3/4
A and B and not(C)
A= -f $fhB= (stat _)[2] & 36C= not $warned{$file}++
ABCresult
0XX0
10X0
1100
1111
39 2 warn "teai: $file is readable by others\n";
40 }
41 19 ▶ while (my $l = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline $fh)) 25 17 42
42 25 $l =~ s/^\s+|\s+$//g;
43 25 ▶ next if $l eq '' || $l =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "" or $l =~ /^#/u 3 22 25
Condition100%3/3
$l eq "" or $l =~ /^#/u
l!l&&r!l&&!r
1222
MC/DC100%2/2
$l eq "" or $l =~ /^#/u
$l eq "" $l =~ /^#/u
Truth table100%3/3
A or B
A= $l eq ""B= $l =~ /^#/u
ABresult
1X1
011
000
44 22 ▶ my ($k, $val) = $l =~ /\A(\w+)\s*=\s*(.*)\z/
Branch: 1 branch
BranchTrueFalseTotal
() = $l =~ /\A(\w+)\s*=\s*(.*)\z/u or App::teai::Err::fail(2, "${file}:$.: bad config line: $l") 21 1 22
45 or App::teai::Err::fail(2, "$file:$.: bad config line: $l");
46 21 ▶ App::teai::Err::fail(2, "$file:$.: unknown config key '$k'") unless $KEYS{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $KEYS{$k} 1 20 21
47 20 $v{$k} = $val;
48 }
49 }
50 elsif ($explicit) {
51 3 App::teai::Err::fail(2, "cannot read TEAI_CONFIG $file: $!");
52 }
53 ▶ elsif (!$!{ENOENT} && !$!{ENOTDIR}) {
Condition66%2/3
$!{'ENOENT'} || $!{'ENOTDIR'}
l!l&&r!l&&!r
302
MC/DC50%1/2
$!{'ENOENT'} || $!{'ENOTDIR'}
$!{'ENOENT'} $!{'ENOTDIR'}
Truth table66%2/3
A || B
A= $!{'ENOENT'}B= $!{'ENOTDIR'}
ABresult
1X1
011
000
54 2 App::teai::Err::fail(2, "cannot read $file: $!");
55 }
56 }
57 20 for my $k (keys %ENVKEY) {
58 100 my $e = _env($ENVKEY{$k});
59 100 ▶ $v{$k} = $e if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 7 93 100
60 }
61 20 ▶ my $url = $v{url} // 'nats://127.0.0.1:4222';
Condition100%2/2
$v{"url"} // "nats://127.0.0.1:4222"
l!l
155
MC/DC100%1/1
$v{"url"} // "nats://127.0.0.1:4222"
$v{"url"}
Truth table100%2/2
A
A= $v{"url"}
Aresult
11
00
62 20 ▶ my ($scheme, $host, $port) = $url =~ m{\A(nats|tls)://(\[[0-9A-Fa-f:.]+\]|[^/:\[\]]+)(?::(\d+))?/?\z}
Branch: 1 branch
BranchTrueFalseTotal
() = $url =~ m(\A(nats|tls)://(\[[0-9A-Fa-f:.]+\]|[^/:\[\]]+)(?::(\d+))?/?\z)u or App::teai::Err::fail(2, "invalid url '${url}'") 19 1 20
63 or App::teai::Err::fail(2, "invalid url '$url'");
64 19 ▶ App::teai::Err::fail(2, "invalid url '$url': bad port") if defined $port && ($port < 1 || $port > 65535);
Branch: 1 branch
BranchTrueFalseTotal
if defined $port and $port < 1 || $port > 65535 3 16 19
Condition100%6/6
defined $port and $port < 1 || $port > 65535
!ll&&!rl&&r
1153
$port < 1 or $port > 65535
l!l&&r!l&&!r
1215
MC/DC100%3/3
defined $port and $port < 1 || $port > 65535
defined $port $port < 1 $port > 65535
Truth table100%4/4
A and B or C
A= defined $portB= $port < 1C= $port > 65535
ABCresult
0XX0
1000
11X1
1011
65 16 $host =~ s/\A\[|\]\z//g;
66 return {
67 url => $url, host => $host, port => $port // 4222, tls => $scheme eq 'tls' ? 1 : 0,
68 user => $v{user}, pass => $v{password}, creds => $v{creds}, tls_ca => $v{tls_ca},
69 16 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$scheme eq 'tls' ? : 2 14 16
Condition100%2/2
$port // 4222
l!l
151
MC/DC100%1/1
$port // 4222
$port
Truth table100%2/2
A
A= $port
Aresult
11
00
70 }
71  
72 13 ▶sub project ($dir = Cwd::getcwd()) {
Subroutine project: called CC=15 SCAR=27.2
Pod documented
73 13 my $id;
74 13 ▶ my $d = Cwd::abs_path($dir) // $dir;
Condition33%1/3
Cwd::abs_path($dir) // $dir
l!l&&r!l&&!r
1300
MC/DC0%0/2
Cwd::abs_path($dir) // $dir
Cwd::abs_path($dir) $dir
Truth table33%1/3
A // B
A= Cwd::abs_path($dir)B= $dir
ABresult
1X1
011
000
75 13 while (1) {
76 48 my $f = "$d/.teai/id";
77 48 ▶ if (stat $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (stat $f) 4 44 48
78 4 ▶ App::teai::Err::fail(2, "cannot read $f: " . (-d _ ? do { $! = EISDIR; "$!" } : 'not a regular file'))
Branch: 2 branches
BranchTrueFalseTotal
unless -f _ 1 3 4
-d _ ? : 1 0 1
79 unless -f _;
80 3 ▶ open my $fh, '<', $f or App::teai::Err::fail(2, "cannot read $f: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $f or App::teai::Err::fail(2, "cannot read ${f}: $!") 2 1 3
81 2 ▶ $id = <$fh> // '';
Condition50%1/2
readline $fh // ""
l!l
20
MC/DC0%0/1
readline $fh // ""
readline $fh
Truth table50%1/2
A
A= readline $fh
Aresult
11
00
82 2 close $fh;
83 2 $id =~ s/^\s+|\s+$//g;
84 2 last;
85 }
86 44 ▶ App::teai::Err::fail(2, "cannot read $f: $!") unless $!{ENOENT} || $!{ENOTDIR};
Branch: 1 branch
BranchTrueFalseTotal
unless $!{"ENOENT"} or $!{"ENOTDIR"} 1 43 44
Condition100%3/3
$!{"ENOENT"} or $!{"ENOTDIR"}
l!l&&r!l&&!r
4211
MC/DC100%2/2
$!{"ENOENT"} or $!{"ENOTDIR"}
$!{"ENOENT"} $!{"ENOTDIR"}
Truth table100%3/3
A or B
A= $!{"ENOENT"}B= $!{"ENOTDIR"}
ABresult
1X1
011
000
87 43 my $up = File::Spec->catdir($d, File::Spec->updir);
88 43 $up = Cwd::abs_path($up);
89 43 ▶ last if !defined $up || $up eq $d;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $up or $up eq $d 8 35 43
Condition66%2/3
not defined $up or $up eq $d
l!l&&r!l&&!r
0835
MC/DC50%1/2
not defined $up or $up eq $d
not defined $up $up eq $d
Truth table66%2/3
not(A) or B
A= not defined $upB= $up eq $d
ABresult
1X1
011
000
90 35 $d = $up;
91 }
92 10 ▶ $id //= _env('TEAI_PROJECT');
Condition100%3/3
$id //= _env("TEAI_PROJECT")
l!l&&r!l&&!r
235
MC/DC100%2/2
$id //= _env("TEAI_PROJECT")
$id _env("TEAI_PROJECT")
Truth table100%3/3
A //= B
A= $idB= _env("TEAI_PROJECT")
ABresult
1X1
011
000
93 10 ▶ return undef unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 5 5 10
94 5 ▶ App::teai::Err::fail(2, "invalid project id '$id'") unless valid_id($id);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($id) 1 4 5
95 4 return $id;
96 }
97  
98 5 ▶sub role () {
Subroutine role: called CC=3 SCAR=11.0
Pod documented
99 5 my $r = _env('TEAI_ROLE');
100 5 ▶ return undef unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 2 3 5
101 3 ▶ App::teai::Err::fail(2, "invalid role '$r'") unless valid_id($r);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($r) 2 1 3
102 1 return $r;
103 }
104  
105 0 ▶sub host () {
Subroutine host: not called CC=5 SCAR=34.0
Pod documented
106 0 ▶ my $h = _env('TEAI_HOST') // (split /\./, (POSIX::uname())[1] // '', 2)[0] // '';
Condition0%0/7
(_env("TEAI_HOST") // (split(/\./u, (POSIX::uname())[1] // "", 2))[0]) // ""
l!l
00
_env("TEAI_HOST") // (split(/\./u, (POSIX::uname())[1] // "", 2))[0]
l!l&&r!l&&!r
000
(POSIX::uname())[1] // ""
l!l
00
MC/DC0%0/2
(_env("TEAI_HOST") // (split(/\./u, (POSIX::uname())[1] // "", 2))[0]) // ""
_env("TEAI_HOST") (split(/\./u, (POSIX::uname())[1] // "", 2))[0]
MC/DC0%0/1
(POSIX::uname())[1] // ""
(POSIX::uname())[1]
Truth table0%0/3
A // B
A= _env("TEAI_HOST")B= (split(/\./u, (POSIX::uname())[1] // "", 2))[0]
ABresult
1X1
011
000
Truth table0%0/2
A
A= (POSIX::uname())[1]
Aresult
11
00
107 0 $h =~ s/[^A-Za-z0-9_-]/_/g;
108 0 $h = substr $h, 0, 64;
109 0 ▶ return length $h ? $h : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
length $h ? : 0 0 0
110 }
111  
112 1 ▶sub agent_of ($session) { (split /-/, $session, 2)[0] }
Subroutine agent_of: called CC=1 SCAR=0.0
Pod documented
113  
114 2 ▶sub session () {
Subroutine session: called CC=4 SCAR=14.1
Pod documented
115 2 my $s = $ENV{TEAI_SESSION};
116 2 ▶ App::teai::Err::fail(2, "no session: run 'teai join' and export TEAI_SESSION")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and length $s 1 1 2
Condition66%2/3
defined $s and length $s
!ll&&!rl&&r
101
MC/DC50%1/2
defined $s and length $s
defined $s length $s
Truth table66%2/3
A and B
A= defined $sB= length $s
ABresult
0X0
100
111
117 unless defined $s && length $s;
118 1 ▶ App::teai::Err::fail(2, "invalid session id '$s'") unless valid_id($s);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($s) 0 1 1
119 1 return $s;
120 }
121  
122 10 ▶sub valid_agent ($agent) { defined $agent && grep({ $_ eq $agent } @AGENTS) ? 1 : 0 }
Subroutine valid_agent: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $agent && grep({$_ eq $agent;} @AGENTS) ? : 6 4 10
Condition66%2/3
defined $agent and grep {$_ eq $agent;} @AGENTS
!ll&&!rl&&r
046
MC/DC50%1/2
defined $agent and grep {$_ eq $agent;} @AGENTS
defined $agent grep {$_ eq $agent;} @AGENTS
Truth table66%2/3
A and B
A= defined $agentB= grep {$_ eq $agent;} @AGENTS
ABresult
0X0
100
111
123  
124 2 ▶sub new_session_id ($agent) {
Subroutine new_session_id: called CC=3 SCAR=11.0
Pod documented
125 2 ▶ App::teai::Err::fail(2, "unknown agent '" . ($agent // '') . "'") unless valid_agent($agent);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_agent($agent) 1 1 2
Condition50%1/2
$agent // ""
l!l
10
MC/DC0%0/1
$agent // ""
$agent
Truth table50%1/2
A
A= $agent
Aresult
11
00
126 1 my @c = ('a' .. 'z', 0 .. 9);
127 1 return "$agent-" . join '', map { $c[int rand @c] } 1 .. 10;
128 }
129  
130 8 ▶sub _safe_dir ($d, $what = 'runtime') {
Subroutine _safe_dir: called CC=8 SCAR=21.0
131 8 my @st = lstat $d;
132 8 ▶ App::teai::Err::fail(3, "unsafe $what dir $d")
Branch: 1 branch
BranchTrueFalseTotal
unless @st and -d _ and not -l _ and $st[4] == $< 3 5 8
Condition77%7/9
@st and -d _ and not -l _ and $st[4] == $<
!ll&&!rl&&r
215
@st and -d _ and not -l _
!ll&&!rl&&r
206
@st and -d _
!ll&&!rl&&r
026
MC/DC50%2/4
@st and -d _ and not -l _ and $st[4] == $<
@st -d _ not -l _ $st[4] == $<
Truth table60%3/5
A and B and not(C) and D
A= @stB= -d _C= not -l _D= $st[4] == $<
ABCDresult
0XXX0
10XX0
110X0
11100
11111
133 unless @st && -d _ && !-l _ && $st[4] == $<;
134 5 ▶ if (($st[2] & 07777) != 0700) {
Branch: 1 branch
BranchTrueFalseTotal
if (($st[2] & 4095) != 448) 1 4 5
135 1 ▶ chmod 0700, $d or App::teai::Err::fail(3, "unsafe $what dir $d");
Branch: 1 branch
BranchTrueFalseTotal
chmod 0700, $d or App::teai::Err::fail(3, "unsafe $what dir $d") 1 0 1
136 }
137 5 return $d;
138 }
139  
140 7 ▶sub runtime_path () {
Subroutine runtime_path: called CC=3 SCAR=14.2
Pod documented
141 return defined $ENV{XDG_RUNTIME_DIR} && length $ENV{XDG_RUNTIME_DIR}
142 7 ▶ ? "$ENV{XDG_RUNTIME_DIR}/teai" : "/tmp/teai-$<";
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'XDG_RUNTIME_DIR'} && length $ENV{'XDG_RUNTIME_DIR'} ? : 7 0 7
Condition33%1/3
defined $ENV{"XDG_RUNTIME_DIR"} and length $ENV{"XDG_RUNTIME_DIR"}
!ll&&!rl&&r
007
MC/DC0%0/2
defined $ENV{"XDG_RUNTIME_DIR"} and length $ENV{"XDG_RUNTIME_DIR"}
defined $ENV{"XDG_RUNTIME_DIR"} length $ENV{"XDG_RUNTIME_DIR"}
Truth table33%1/3
A and B
A= defined $ENV{"XDG_RUNTIME_DIR"}B= length $ENV{"XDG_RUNTIME_DIR"}
ABresult
0X0
100
111
143 }
144  
145 7 ▶sub _private_dir ($d, $what) {
Subroutine _private_dir: called CC=3 SCAR=11.0
146 7 ▶ unless (lstat $d) {
Branch: 1 branch
BranchTrueFalseTotal
unless (lstat $d) 1 6 7
147 1 require File::Path;
148 1 ▶ eval { File::Path::make_path($d, { mode => 0700 }); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { File::Path::make_path($d, {"mode", 448}); 1 } } or App::teai::Err::fail(3, "cannot create $what dir $d") 1 0 1
149 or App::teai::Err::fail(3, "cannot create $what dir $d");
150 }
151 7 return _safe_dir($d, $what);
152 }
153  
154 7 ▶sub runtime_dir () { _private_dir(runtime_path(), 'runtime') }
Subroutine runtime_dir: called CC=1 SCAR=0.0
Pod documented
155  
156 0 ▶sub state_dir () {
Subroutine state_dir: not called CC=6 SCAR=37.4
Pod documented
157 0 my $x = _env('XDG_STATE_HOME');
158 0 ▶ my $home = _env('HOME') // (getpwuid $<)[7];
Condition0%0/3
_env("HOME") // (getpwuid $<)[7]
l!l&&r!l&&!r
000
MC/DC0%0/2
_env("HOME") // (getpwuid $<)[7]
_env("HOME") (getpwuid $<)[7]
Truth table0%0/3
A // B
A= _env("HOME")B= (getpwuid $<)[7]
ABresult
1X1
011
000
159 0 ▶ my $d = defined $x && $x =~ m{\A/} ? "$x/teai"
Branch: 2 branches
BranchTrueFalseTotal
defined $x && $x =~ m[\A/]u ? : 0 0 0
defined $home && length $home ? : 0 0 0
Condition0%0/6
defined $x and $x =~ m[\A/]u
!ll&&!rl&&r
000
defined $home and length $home
!ll&&!rl&&r
000
MC/DC0%0/2
defined $x and $x =~ m[\A/]u
defined $x $x =~ m[\A/]u
MC/DC0%0/2
defined $home and length $home
defined $home length $home
Truth table0%0/3
A and B
A= defined $xB= $x =~ m[\A/]u
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $homeB= length $home
ABresult
0X0
100
111
160 : defined $home && length $home ? "$home/.local/state/teai"
161 : App::teai::Err::fail(3, 'cannot find the state dir: no HOME');
162 0 return _private_dir($d, 'state');
163 }
164  
165 3 ▶sub reader_lock ($session, $nowait = 0) {
Subroutine reader_lock: called CC=7 SCAR=19.5
Pod documented
166 3 ▶ App::teai::Err::fail(2, "invalid session id '$session'") unless valid_id($session);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($session) 0 3 3
167 3 my $path = runtime_dir() . "/$session.reader";
168 3 ▶ open my $fh, '>>', $path or App::teai::Err::fail(3, "cannot open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $path or App::teai::Err::fail(3, "cannot open ${path}: $!") 3 0 3
169 3 ▶ my $op = $nowait ? LOCK_EX | LOCK_NB : LOCK_EX;
Branch: 1 branch
BranchTrueFalseTotal
$nowait ? : 2 1 3
170 3 while (1) {
171 4 ▶ return $fh if flock $fh, $op;
Branch: 1 branch
BranchTrueFalseTotal
if flock $fh, $op 2 2 4
172 2 ▶ next if $!{EINTR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINTR"} 1 1 2
173 1 return undef;
174 }
175 }
176  
177 41 1;
178 __END__
« lib/App/teai/Lead.pm ↑ Summary lib/App/teai/Lock.pm »