| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2003-2022 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # Depends: () ; right? Haven't verified closely. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Chj::xperlfunc | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | my $pid = xspawn @files; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | print "Did it!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | wait; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | print "The process (was pid $pid) gave ".($? >> 8)."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | Wrappers around core functions that throw exceptions on errors. Plus | ||||||||||||||||||||||||||||||||||||||||||
| 26 | some simple utilities, exported optionally (explicitely or as part of | ||||||||||||||||||||||||||||||||||||||||||
| 27 | the ":all" tag.) | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =item xsystem(..) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | Croaks if the command could not be started (i.e. system gave -1). | ||||||||||||||||||||||||||||||||||||||||||
| 36 | Returns the exit code of the program ( == $?); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =item xxsystem(..) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | Same as xsystem but also croaks if $? != 0. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | =item xsystem_safe(..) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | =item xxsystem_safe(..) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | Same as the *xsystem calls but never run a shell, even if only one | ||||||||||||||||||||||||||||||||||||||||||
| 47 | argument is given. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 ADDITIONAL FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | These are exported by default. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =item xstat(path) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =item xlstat(path) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =item Xstat(path) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =item Xlstat(path) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | These are wrappers around stat; the x* functions die, the X* ones | ||||||||||||||||||||||||||||||||||||||||||
| 66 | return undef on ENOENT errors (and still croak on other errors like | ||||||||||||||||||||||||||||||||||||||||||
| 67 | permission problems). When successful, they return objects (based on | ||||||||||||||||||||||||||||||||||||||||||
| 68 | array with the stat return values) with accessor methods. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | If $Chj::xperlfunc::time_hires is true, these will return floating | ||||||||||||||||||||||||||||||||||||||||||
| 71 | point number strings for time stamps. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =item xlocaltime() or xlocaltime(unixtime) | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | These are wrappers around localtime; it never dies, but returns | ||||||||||||||||||||||||||||||||||||||||||
| 76 | objects (based on an array with the localtime values) with accessor | ||||||||||||||||||||||||||||||||||||||||||
| 77 | methods (including chainable setters). Additionally to the normal | ||||||||||||||||||||||||||||||||||||||||||
| 78 | accessors, 'Year' and 'Mon' exist, which are in the "normal" | ||||||||||||||||||||||||||||||||||||||||||
| 79 | (19xx..203x, 1..31) ranges, and 'Wday' which is 1..7 starting on | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Sunday and 'wDay' which is 0..6 starting on Monday. They also have a | ||||||||||||||||||||||||||||||||||||||||||
| 81 | unixtime function to convert back to unixtime--this requires | ||||||||||||||||||||||||||||||||||||||||||
| 82 | Time::Local to be loaded explicitely. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 SPECIAL FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | These may be imported explicitely on demand. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =item xfork_(&) | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | Forks then runs the passed thunk in the child. The child process | ||||||||||||||||||||||||||||||||||||||||||
| 95 | captures any uncaught exceptions and runs exit(1), otherwise upon | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ending the thunk exit(0). | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =item xLmtimed($path), XLmtimed($path) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | Those call lstat first, then if it's a symlink, also stat, then return | ||||||||||||||||||||||||||||||||||||||||||
| 101 | an object with an mtime method that returns the newer mtime of the | ||||||||||||||||||||||||||||||||||||||||||
| 102 | two. Other methods are is_link (about the original path) and is_dir | ||||||||||||||||||||||||||||||||||||||||||
| 103 | and is_file (about the target path). | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | NOTE: those only call lstat and stat once, they don't check whether | ||||||||||||||||||||||||||||||||||||||||||
| 106 | the target is reached through several intermediate links or whether | ||||||||||||||||||||||||||||||||||||||||||
| 107 | any directory in any of the paths has newer mtime. Thus the result | ||||||||||||||||||||||||||||||||||||||||||
| 108 | can't be relied on for security (well, couldn't anyway since mtime can | ||||||||||||||||||||||||||||||||||||||||||
| 109 | be set, of course). | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | =item xLmtime($path), XLmtime($path) | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | Same as xLmtimed, XLmtimed but return the mtime value (or undef) | ||||||||||||||||||||||||||||||||||||||||||
| 114 | instead of a wrapper object. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =item xspawn($;) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Like xsystem, but returns as soon as the command has been started successfully, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | leaving it running in the background. You may and should wait() for it some | ||||||||||||||||||||||||||||||||||||||||||
| 120 | time, you may also get SIGCHLD. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =item xlaunch($;) | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | Launch a program fully in the background, in a separate session, and with | ||||||||||||||||||||||||||||||||||||||||||
| 125 | double fork so that we don't need to (and never may) wait for it ever. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | Using a pipe, it can still find out if the launch was successful or not. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | =item xmvmkdir(first,newplace [,strict]) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | Move directory 'first' to 'newplace', then create a new empty dir at | ||||||||||||||||||||||||||||||||||||||||||
| 131 | place 'first' with same permissions as 'newplace'. Only root can | ||||||||||||||||||||||||||||||||||||||||||
| 132 | recreate owners different than current user and groups that the user | ||||||||||||||||||||||||||||||||||||||||||
| 133 | is not part in, of course. If 'strict' is true, croaks if it can't | ||||||||||||||||||||||||||||||||||||||||||
| 134 | recreate all permission details. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =item pathref = xtmpdir_with_paragon(pathtoexistingdir [,strict]) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | Create new directory using pathtoexistingdir as paragon. The new directoy | ||||||||||||||||||||||||||||||||||||||||||
| 139 | is placed into the same parent dir, with a dot prepended and .tmp and | ||||||||||||||||||||||||||||||||||||||||||
| 140 | a random number appended. The permissions are recreated. A reference of t | ||||||||||||||||||||||||||||||||||||||||||
| 141 | he path to the new directory is returned. (Reason to use a reference: | ||||||||||||||||||||||||||||||||||||||||||
| 142 | it's a lightweight object; upon deleting the last reference, it will | ||||||||||||||||||||||||||||||||||||||||||
| 143 | try to remove the tmpdir if empty.) | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =item xmkdir_with_paragon UNTESTED | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =item xlinkunlink $source,$target | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | Has the same effect as xrename $source,$target except that it | ||||||||||||||||||||||||||||||||||||||||||
| 150 | won't overwrite $target if it already exists. This is done by using | ||||||||||||||||||||||||||||||||||||||||||
| 151 | link and unlink instead of rename. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =item xxcarefulrename $source,$target | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | xlinkunlink doesn't work for directories, or not always under grsec. | ||||||||||||||||||||||||||||||||||||||||||
| 156 | xxcarefulrename does resort to rename if hardlinks don't work. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | But note: this is only careful, not guaranteed to be safe. | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =item xlinkreplace $source,$target | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | This makes a new hardlink from source to target, potentially replacing | ||||||||||||||||||||||||||||||||||||||||||
| 162 | a previous target. All the same it does the replace atomically. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | (It works by creating a link to a temporary location then rename.) | ||||||||||||||||||||||||||||||||||||||||||
| 164 | (Hm, strange function name?) | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =item xfileno $string_or_FH | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | Does work with both filehandles and integer strings. Croaks if it's | ||||||||||||||||||||||||||||||||||||||||||
| 169 | neither or there's an error. | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | =item basename $pathstring [,$suffix(es) [,$insensitive]] | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | Same as the shell util of the same name, except that it croaks in a | ||||||||||||||||||||||||||||||||||||||||||
| 174 | few cases (when an empty string is given, or when the given suffix | ||||||||||||||||||||||||||||||||||||||||||
| 175 | doesn't match). | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =item dirname $pathstring | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | Same as the shell util (or about as my old FolderOfThisFile function), | ||||||||||||||||||||||||||||||||||||||||||
| 180 | except that it croaks if dirname of "/" or "." is requested. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | =item xmkdir_p $pathstring | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | Works like unix's "mkdir -p": return false if the directory already | ||||||||||||||||||||||||||||||||||||||||||
| 185 | exists, true if it (and, if necessary, it's parent(s)) has(/have) been | ||||||||||||||||||||||||||||||||||||||||||
| 186 | created, croaks if some error happens on the way. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | =item xlink_p $frompath, $topath | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | xlink's $frompath to $topath but | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | =head1 NOTE | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||||||||||||||||||||||||
| 197 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | #' | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | package Chj::xperlfunc; | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 80 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 80 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 80 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 80 | ▶ | use Exporter "import"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 80 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||
| 210 | xfork | ||||||||||||||||||||||||||||||||||||||||||
| 211 | xfork_ | ||||||||||||||||||||||||||||||||||||||||||
| 212 | xexec | ||||||||||||||||||||||||||||||||||||||||||
| 213 | xexec_safe | ||||||||||||||||||||||||||||||||||||||||||
| 214 | xsystem | ||||||||||||||||||||||||||||||||||||||||||
| 215 | xxsystem | ||||||||||||||||||||||||||||||||||||||||||
| 216 | xsystem_safe | ||||||||||||||||||||||||||||||||||||||||||
| 217 | xxsystem_safe | ||||||||||||||||||||||||||||||||||||||||||
| 218 | xrename | ||||||||||||||||||||||||||||||||||||||||||
| 219 | xmkdir | ||||||||||||||||||||||||||||||||||||||||||
| 220 | xrmdir | ||||||||||||||||||||||||||||||||||||||||||
| 221 | xchmod | ||||||||||||||||||||||||||||||||||||||||||
| 222 | xchown | ||||||||||||||||||||||||||||||||||||||||||
| 223 | xchdir | ||||||||||||||||||||||||||||||||||||||||||
| 224 | xstat | ||||||||||||||||||||||||||||||||||||||||||
| 225 | xlstat | ||||||||||||||||||||||||||||||||||||||||||
| 226 | Xstat | ||||||||||||||||||||||||||||||||||||||||||
| 227 | Xlstat | ||||||||||||||||||||||||||||||||||||||||||
| 228 | xlocaltime | ||||||||||||||||||||||||||||||||||||||||||
| 229 | xreadlink | ||||||||||||||||||||||||||||||||||||||||||
| 230 | xunlink | ||||||||||||||||||||||||||||||||||||||||||
| 231 | xlink | ||||||||||||||||||||||||||||||||||||||||||
| 232 | xsymlink | ||||||||||||||||||||||||||||||||||||||||||
| 233 | xutime | ||||||||||||||||||||||||||||||||||||||||||
| 234 | xkill | ||||||||||||||||||||||||||||||||||||||||||
| 235 | xeval | ||||||||||||||||||||||||||||||||||||||||||
| 236 | xwaitpid | ||||||||||||||||||||||||||||||||||||||||||
| 237 | xxwaitpid | ||||||||||||||||||||||||||||||||||||||||||
| 238 | xwait | ||||||||||||||||||||||||||||||||||||||||||
| 239 | xxwait | ||||||||||||||||||||||||||||||||||||||||||
| 240 | xsysread | ||||||||||||||||||||||||||||||||||||||||||
| 241 | xchroot | ||||||||||||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 80 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 244 | xspawn | ||||||||||||||||||||||||||||||||||||||||||
| 245 | xlaunch | ||||||||||||||||||||||||||||||||||||||||||
| 246 | xmvmkdir | ||||||||||||||||||||||||||||||||||||||||||
| 247 | xmkdir_with_paragon | ||||||||||||||||||||||||||||||||||||||||||
| 248 | xtmpdir_with_paragon | ||||||||||||||||||||||||||||||||||||||||||
| 249 | xlinkunlink | ||||||||||||||||||||||||||||||||||||||||||
| 250 | xlinkreplace | ||||||||||||||||||||||||||||||||||||||||||
| 251 | xxcarefulrename | ||||||||||||||||||||||||||||||||||||||||||
| 252 | xfileno | ||||||||||||||||||||||||||||||||||||||||||
| 253 | basename | ||||||||||||||||||||||||||||||||||||||||||
| 254 | dirname | ||||||||||||||||||||||||||||||||||||||||||
| 255 | xmkdir_p | ||||||||||||||||||||||||||||||||||||||||||
| 256 | xlink_p | ||||||||||||||||||||||||||||||||||||||||||
| 257 | xgetpwnam | ||||||||||||||||||||||||||||||||||||||||||
| 258 | xgetgrnam | ||||||||||||||||||||||||||||||||||||||||||
| 259 | caching_getpwnam | ||||||||||||||||||||||||||||||||||||||||||
| 260 | caching_getgrnam | ||||||||||||||||||||||||||||||||||||||||||
| 261 | xprint | ||||||||||||||||||||||||||||||||||||||||||
| 262 | xprintln | ||||||||||||||||||||||||||||||||||||||||||
| 263 | xLmtimed | ||||||||||||||||||||||||||||||||||||||||||
| 264 | XLmtimed | ||||||||||||||||||||||||||||||||||||||||||
| 265 | xLmtime | ||||||||||||||||||||||||||||||||||||||||||
| 266 | XLmtime | ||||||||||||||||||||||||||||||||||||||||||
| 267 | min max | ||||||||||||||||||||||||||||||||||||||||||
| 268 | fstype_for_device | ||||||||||||||||||||||||||||||||||||||||||
| 269 | xgetfile_utf8 xslurp | ||||||||||||||||||||||||||||||||||||||||||
| 270 | maybe_getfile_utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | # would we really want to export these?: | ||||||||||||||||||||||||||||||||||||||||||
| 274 | #caching_getpwuid | ||||||||||||||||||||||||||||||||||||||||||
| 275 | #caching_getgrgid | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 80 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 80 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 80 | ▶ | use FP::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 80 | ▶ | use Chj::singlequote 'singlequote_many'; # the only dependency so far | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 80 | ▶ | use Chj::Unix::Exitcode qw(exitcode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 80 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 80 | ▶ | if ($^O eq 'linux') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 80 | eval 'sub EEXIST() {17} sub ENOENT() {2}'; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 80 | ▶ | die if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | eval 'use POSIX "EEXIST","ENOENT"'; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | die if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | sub xfork { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xfork: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $pid = fork; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | defined $pid or croak "xfork: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $pid | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | # thread-like API; incomplete, for sure. | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub xfork_(&) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xfork_: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my ($thunk) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $pid = xfork; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $pid | |||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | # kinda run in a new dynamic context, please... (evil, | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # e.g. $SIG{__WARN__} is still set; do all of this?) | ||||||||||||||||||||||||||||||||||||||||||
| 311 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | &$thunk(); | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # drop return value (transfer via pipe? 'No.') | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | exit 0; # POSIX::_exit ? no? Anyway docs say otherwise. | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | } || do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | warn "uncaught exception in subprocess $$, exiting: $@"; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | exit 1; # POSIX::_exit ? no? | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub xexec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xexec: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | exec @_; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | croak "xexec " . singlequote_many(@_) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 14 | ▶ | sub xexec_safe { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xexec_safe: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 14 | exec { $_[0] } @_; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | croak "xexec_safe " . singlequote_many(@_) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | sub xspawn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xspawn: not called CC=9 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | croak "xspawn: too few arguments" unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | local $^F = 0; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | pipe my $read, my $write or die "pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if (my $pid = xfork) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | close $write or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $errstr = <$read>; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | chomp $errstr; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | close $read or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if (length $errstr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | croak "xspawn: can't exec \"$_[0]\": $errstr"; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | return $pid; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | close $read or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | exec @_; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | select $write or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $| = 1; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | print $!; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | POSIX::_exit(127); | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | sub xlaunch | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | { ## NA: todo: noch nicht fertig, insbesondere geht kommunikation exec failure nich bis zum parent. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlaunch: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $pid = xfork; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ($pid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | waitpid $pid, 0; # ! | |||||||||||||||||||||||||||||||||||||||||
| 368 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | # evtl. set session zeugs. | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | xspawn @_; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | POSIX::_exit(0); # ! | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | sub xsystem { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsystem: not called CC=3 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | @_ > 0 or croak "xsystem: missing arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | (system @_) >= 0 or croak "xsystem: could not start command '$_[0]': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $? | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | sub xxsystem { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xxsystem: not called CC=4 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | @_ > 0 or croak "xxsystem: missing arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | (system @_) >= 0 or croak "xxsystem: could not start command '$_[0]': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | $? == 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | or croak "xxsystem: process '$_[0]' terminated with " . exitcode($?); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub xsystem_safe { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsystem_safe: not called CC=3 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | @_ > 0 or croak "xsystem_safe: missing arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | (system { $_[0] } @_) >= 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | or croak "xsystem_safe: could not start command '$_[0]': $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $? | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 25 | ▶ | sub xxsystem_safe { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xxsystem_safe: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 25 | ▶ | @_ > 0 or croak "xxsystem_safe: missing arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 80 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 25 | ▶ | (system { $_[0] } @_) >= 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | or croak "xxsystem_safe: could not start command '$_[0]': $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 25 | ▶ | $? == 0 or croak "xxsystem_safe: process terminated with " . exitcode($?); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub xwaitpid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xwaitpid: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | @_ >= 1 and @_ <= 2 or fp_croak_arity "1-2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ >= 1 and @_ <= 2
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1
@_ <= 2
Truth table0%0/3
A and B
A= @_ >= 1B= @_ <= 2
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my ($pid, $flags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | defined $flags or $flags = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $kid = waitpid $pid, $flags; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | die "xwaitpid ($pid,$flags): no child process" if $kid < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | # ^ "no such child" but pid -1 is okay right? so.. | ||||||||||||||||||||||||||||||||||||||||||
| 415 | #$? # hm drop $kid? build tuple? ? | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $kid | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub xxwaitpid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xxwaitpid: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | @_ >= 1 and @_ <= 2 or fp_croak_arity "1-2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ >= 1 and @_ <= 2
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1
@_ <= 2
Truth table0%0/3
A and B
A= @_ >= 1B= @_ <= 2
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my ($pid, $flags) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | defined $flags or $flags = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my $kid = xwaitpid $pid, $flags; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | $? == 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | or die "xxwaitpid ($pid,$flags): child process terminated with " | ||||||||||||||||||||||||||||||||||||||||||
| 426 | . exitcode($?); | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $kid | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | sub xwait { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xwait: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $kid = wait; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | defined $kid or die "xwait: $!"; # when can this happen? EINTR? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | wantarray ? ($kid, $?) : $kid ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub xxwait { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xxwait: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $kid = wait; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | defined $kid or die "xxwait: $!"; # when can this happen? EINTR? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $status = $?; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | $status == 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | or die "xxwait: child process $kid terminated with " . exitcode($?); | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $kid | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub xrename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xrename: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | rename $_[0], $_[1] or croak "xrename(" . join(", ", @_) . "): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub xlinkunlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlinkunlink: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | link $_[0], $_[1] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | or croak "xlinkunlink(" | ||||||||||||||||||||||||||||||||||||||||||
| 456 | . join(", ", @_) | ||||||||||||||||||||||||||||||||||||||||||
| 457 | . "): can't link to target: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | unlink $_[0] or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my $err = "$!"; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $res = unlink $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | # ^ could this ever be dangerous? answer is yes. does it bother me? | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | croak "xlinkunlink(" | |||||||||||||||||||||||||||||||||||||||||
| 465 | . join(", ", @_) | ||||||||||||||||||||||||||||||||||||||||||
| 466 | . "): can't unlink source: $err, so removed target again"; | ||||||||||||||||||||||||||||||||||||||||||
| 467 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | croak "xlinkunlink(" | |||||||||||||||||||||||||||||||||||||||||
| 469 | . join(", ", @_) | ||||||||||||||||||||||||||||||||||||||||||
| 470 | . "): can't unlink source: $err, " | ||||||||||||||||||||||||||||||||||||||||||
| 471 | . "additionally an error occured while trying to unlink " | ||||||||||||||||||||||||||||||||||||||||||
| 472 | . "the target again: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | # Since xlinkunlink doesn't work for directories, or not always under | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # grsec: (But note: it's careful, not guaranteed to be safe.) | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | sub xxcarefulrename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xxcarefulrename: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my ($source, $dest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | if (link $source, $dest) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | unlink $source or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $err = "$!"; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my $res = unlink $dest; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | # ^ could this ever be dangerous? answer is yes. does it bother me? | ||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | croak "xxcarefulrename(" | |||||||||||||||||||||||||||||||||||||||||
| 490 | . join(", ", @_) | ||||||||||||||||||||||||||||||||||||||||||
| 491 | . "): can't unlink source: $err, so removed target again"; | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | # note: no need to goto rename-branch, since the | ||||||||||||||||||||||||||||||||||||||||||
| 494 | # difficult cases either won't come here (grsec | ||||||||||||||||||||||||||||||||||||||||||
| 495 | # hardlink restriction) or won't be helped by rename | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # (non-owned source file in sticky source dir (we're | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # not even talking about the case where both source | ||||||||||||||||||||||||||||||||||||||||||
| 498 | # and target are in sticky dirs..)). | ||||||||||||||||||||||||||||||||||||||||||
| 499 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | croak "xxcarefulrename(" | |||||||||||||||||||||||||||||||||||||||||
| 501 | . join(", ", @_) | ||||||||||||||||||||||||||||||||||||||||||
| 502 | . "): can't unlink source: $err, additionally an error " | ||||||||||||||||||||||||||||||||||||||||||
| 503 | . "occured while trying to unlink the target again: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 506 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | if (lstat $dest) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | # (yes, link too already fails if target exists as a | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # dangling symlink) | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | croak "xxcarefulrename: target '$dest' already exists"; | |||||||||||||||||||||||||||||||||||||||||
| 512 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | rename $source, $dest | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | or croak "xxcarefulrename(" . join(", ", @_) . "): $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | sub xlinkreplace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlinkreplace: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my ($source, $dest) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 522 | ## schon wieder dieser temporary try mechanismus. sollte ich dringend eine generische func oder ein makro dafür haben theoretisch | ||||||||||||||||||||||||||||||||||||||||||
| 523 | # nun im gegensatz zu Tempfile.pm brauchen wir kein eval hier. Aber auch das waer ja per func/macro machbar | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my $path; | |||||||||||||||||||||||||||||||||||||||||
| 525 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | for (1 .. 3) { | |||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $! = 0; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $rand = int(rand(99999) * 100000 + rand(99999)); | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | # well, not good enough for dangerous cases nor reasonable for | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # non-dangerous cases? | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $path = "$source.tmp$rand~"; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | last TRY if link $source, $path; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | croak "xlinkreplace: failed 3 attempts to create hardlinks from " | |||||||||||||||||||||||||||||||||||||||||
| 536 | . "'$source' to e.g. '$path': $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | rename $path, $dest | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | or croak "xlinkreplace: could not rename '$path' to '$dest': $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | sub xmkdir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmkdir: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | mkdir $_[0] or croak "xmkdir($_[0]): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | } elsif (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | mkdir $_[0], $_[1] or croak "xmkdir(" . join(", ", @_) . "): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | croak "xmkdir: wrong number of arguments"; | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | sub xrmdir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xrmdir: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | rmdir $_[0] or croak "xrmdir($_[0]): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | croak "xrmdir: wrong number of arguments"; | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | sub xchmod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xchmod: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | @_ >= 1 or croak "xchmod: not enoug arguments"; # should it be >1? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | chmod shift, @_ or croak "xchmod: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub xchown { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xchown: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | @_ >= 2 or croak "xchown: not enoug arguments"; # should it be >2? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | chown shift, shift, @_ or croak "xchown: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | sub xchdir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xchdir: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | chdir $_[0] or croak "xchdir '$_[0]': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | 80 | our $time_hires = 0; | |||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | sub stat_possiblyhires { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stat_possiblyhires: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | if ($time_hires) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | require Time::HiRes; # (that's not slow, right?) | |||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | Time::HiRes::stat($_[0]) | |||||||||||||||||||||||||||||||||||||||||
| 582 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | Time::HiRes::stat($_) | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | stat($_[0]) | |||||||||||||||||||||||||||||||||||||||||
| 589 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | stat($_) | |||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | 96 | ▶ | sub lstat_possiblyhires { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lstat_possiblyhires: called CC=6 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 596 | 96 | ▶ | if ($time_hires) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | require Chj::Linux::HiRes; | |||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | Chj::Linux::HiRes::lstat($_[0]) | |||||||||||||||||||||||||||||||||||||||||
| 601 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | Chj::Linux::HiRes::lstat($_) | |||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 96 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 96 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 96 | lstat($_[0]) | |||||||||||||||||||||||||||||||||||||||||
| 608 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | lstat($_) | |||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | # XX: should provide a newly named function to give the object, | ||||||||||||||||||||||||||||||||||||||||||
| 615 | # instead of using wantarray. Have xstat behave like the Perl builtin | ||||||||||||||||||||||||||||||||||||||||||
| 616 | # (and then possibly drop and replace by another solution from | ||||||||||||||||||||||||||||||||||||||||||
| 617 | # core/CPAN). | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | sub xstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xstat: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | @_ <= 1 or croak "xstat: too many arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | @r = stat_possiblyhires(@_ ? @_ : $_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | @r or croak(@_ ? "xstat: '@_': $!" : "xstat: '$_': $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | my $wantarray = wantarray; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | @r | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | } elsif (defined $wantarray) { | |||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | my $self = \@r; | |||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | bless $self, 'Chj::xperlfunc::xstat' | |||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | # XX ditto | ||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | sub xlstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlstat: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | @_ <= 1 or croak "xlstat: too many arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | @r = lstat_possiblyhires(@_ ? @_ : $_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | @r or croak(@_ ? "xlstat: '@_': $!" : "xlstat: '$_': $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | my $wantarray = wantarray; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | @r | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | } elsif (defined $wantarray) { | |||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | my $self = \@r; | |||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | bless $self, 'Chj::xperlfunc::xstat' | |||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 80 | ▶ | use Carp 'cluck'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | # XX ditto | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | sub Xstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Xstat: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | @_ <= 1 or croak "Xstat: too many arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | @r = stat_possiblyhires(@_ ? @_ : $_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | @r or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | if ($! == ENOENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 657 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | croak(@_ ? "Xstat: '@_': $!" : "Xstat: '$_': $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | my $wantarray = wantarray; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | cluck "Xstat call in array context doesn't make sense"; | |||||||||||||||||||||||||||||||||||||||||
| 664 | @r | ||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | } elsif (defined $wantarray) { | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | bless \@r, 'Chj::xperlfunc::xstat' | |||||||||||||||||||||||||||||||||||||||||
| 667 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | cluck "Xstat call in void context doesn't make sense"; | |||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | # XX ditto | ||||||||||||||||||||||||||||||||||||||||||
| 673 | 96 | ▶ | sub Xlstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Xlstat: called CC=8 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | 96 | ▶ | @_ <= 2 or croak "Xlstat: too many arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | 96 | my ($path, $accept_errors) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 676 | 96 | ▶ | $path = $_ unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 96 | my @r = lstat_possiblyhires($path); | |||||||||||||||||||||||||||||||||||||||||
| 678 | 96 | ▶ | @r or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | 16 | ▶ | if ($accept_errors or $! == ENOENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$accept_errors or $! == 2
MC/DC0%0/2
$accept_errors or $! == 2
$accept_errors
$! == 2
Truth table33%1/3
A or B
A= $accept_errorsB= $! == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 681 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | croak("Xlstat: '$path': $!"); | |||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 685 | 80 | my $wantarray = wantarray; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 686 | 80 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | cluck "Xlstat call in array context doesn't make sense"; | |||||||||||||||||||||||||||||||||||||||||
| 688 | @r | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | } elsif (defined $wantarray) { | |||||||||||||||||||||||||||||||||||||||||
| 690 | 80 | bless \@r, 'Chj::xperlfunc::xstat' | |||||||||||||||||||||||||||||||||||||||||
| 691 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | cluck "Xlstat call in void context doesn't make sense"; | |||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | # caching variants of perlfuncs: | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 320 | ▶ | sub mk_caching_getANYid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mk_caching_getANYid: called CC=1 SCAR=4.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 320 | my ($function, $scalarindex, $methodname) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 320 | my %cache; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | if (defined $id) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | my $v; | |||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | if (not defined($v = $cache{$id})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $v = [&$function($id)]; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $cache{$id} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | wantarray ? @$v : $$v[$scalarindex] ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | croak "$methodname: got undefined value"; | |||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||
| 715 | 320 | } | |||||||||||||||||||||||||||||||||||||||||
| 716 | *caching_getpwuid | ||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | = mk_caching_getANYid(sub { getpwuid $_[0] }, 0, "caching_getpwuid"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | *caching_getgrgid | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | = mk_caching_getANYid(sub { getgrgid $_[0] }, 0, "caching_getgrgid"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | *caching_getpwnam | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | = mk_caching_getANYid(sub { getpwnam $_[0] }, 2, "caching_getpwnam"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | *caching_getgrnam | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | = mk_caching_getANYid(sub { getgrnam $_[0] }, 2, "caching_getgrnam"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||
| 726 | 80 | our $fstype_for_device; | |||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | sub fstype_for_device_init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fstype_for_device_init: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | open my $mounts, "<", "/proc/mounts" or die "/proc/mounts: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | my %t; | |||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | while (<$mounts>) { ## no critic, $_ is localized | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | my @f = split / /, $_; | |||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | my ($_dev, $mountpoint, $fstype) = @f; | |||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fstype eq "rootfs" or $fstype eq "autofs"
MC/DC0%0/2
$fstype eq "rootfs" or $fstype eq "autofs"
$fstype eq "rootfs"
$fstype eq "autofs"
Truth table0%0/3
A or B
A= $fstype eq "rootfs"B= $fstype eq "autofs"
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 739 | $fstype eq "rootfs" | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | # stupid Linux, not only source but also fs type is shown | ||||||||||||||||||||||||||||||||||||||||||
| 742 | # as rootfs. | ||||||||||||||||||||||||||||||||||||||||||
| 743 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 744 | or ( | ||||||||||||||||||||||||||||||||||||||||||
| 745 | $fstype eq "autofs" | ||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | # more stupid: entry with systemd-1 source, then later | ||||||||||||||||||||||||||||||||||||||||||
| 748 | # with binfmt_misc source and fstype | ||||||||||||||||||||||||||||||||||||||||||
| 749 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 750 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 751 | { | ||||||||||||||||||||||||||||||||||||||||||
| 752 | # Ignore and count on the second entry from /proc/mounts | ||||||||||||||||||||||||||||||||||||||||||
| 753 | # for the same mount. | ||||||||||||||||||||||||||||||||||||||||||
| 754 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | if (defined(my $s = Xlstat($mountpoint, 1))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $dev = $s->dev; | |||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | if (defined $t{$dev}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | $t{$dev} eq $fstype | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | or die | ||||||||||||||||||||||||||||||||||||||||||
| 760 | "entry for '$dev' was previously set to '$t{$dev}', now '$fstype'"; | ||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $t{ $s->dev } = $fstype; | |||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | # else silently ignore, presumably the fs should be reachable | ||||||||||||||||||||||||||||||||||||||||||
| 767 | # at another location then, or the $dev in question would | ||||||||||||||||||||||||||||||||||||||||||
| 768 | # never be found by that user. OK? | ||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | close $mounts or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | $fstype_for_device = \%t; | |||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | ▶ | sub fstype_for_device { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fstype_for_device: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my ($dev) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | my $t = $fstype_for_device->{$dev}; | |||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | ▶ | if (!defined $t) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | fstype_for_device_init; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $t = $fstype_for_device->{$dev}; | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | defined $t or die "no fstype found for device $dev"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | $t | |||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | 80 | package Chj::xperlfunc::xstat { | |||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | # (Alternative to arrays: hashes, so that slices like | ||||||||||||||||||||||||||||||||||||||||||
| 789 | # ->{"dev","ino"} could be done? But so what.) | ||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | sub dev { shift->[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dev: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | sub ino { shift->[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ino: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | sub mode { shift->[2] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | ▶ | sub nlink { shift->[3] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nlink: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub uid { shift->[4] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | sub gid { shift->[5] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | sub rdev { shift->[6] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rdev: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | sub size { shift->[7] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | sub atime { shift->[8] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
atime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 80 | ▶ | sub mtime { shift->[9] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mtime: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | ▶ | sub ctime { shift->[10] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ctime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | sub blksize { shift->[11] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blksize: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | sub blocks { shift->[12] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blocks: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | sub set_dev { my $s = shift; ($s->[0]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_dev: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | sub set_ino { my $s = shift; ($s->[1]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_ino: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | ▶ | sub set_mode { my $s = shift; ($s->[2]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_mode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | sub set_nlink { my $s = shift; ($s->[3]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_nlink: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | sub set_uid { my $s = shift; ($s->[4]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_uid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | ▶ | sub set_gid { my $s = shift; ($s->[5]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_gid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | sub set_rdev { my $s = shift; ($s->[6]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_rdev: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | sub set_size { my $s = shift; ($s->[7]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_size: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | sub set_atime { my $s = shift; ($s->[8]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_atime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | sub set_mtime { my $s = shift; ($s->[9]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_mtime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | ▶ | sub set_ctime { my $s = shift; ($s->[10]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_ctime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | sub set_blksize { my $s = shift; ($s->[11]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_blksize: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | sub set_blocks { my $s = shift; ($s->[12]) = @_; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_blocks: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | # test helpers: | ||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | sub permissions { shift->[2] & 07777 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
permissions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | sub permissions_oct { sprintf('%o', shift->permissions) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
permissions_oct: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | sub permissions_u { (shift->[2] & 00700) >> 6 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
permissions_u: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | sub permissions_g { (shift->[2] & 00070) >> 3 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
permissions_g: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | sub permissions_o { shift->[2] & 00007 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
permissions_o: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | sub permissions_s { (shift->[2] & 07000) >> 9 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
permissions_s: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | sub setuid { !!(shift->[2] & 04000) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setuid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | # ^ I have no desire to put is_ in front. | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | sub setgid { !!(shift->[2] & 02000) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setgid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | # sticky is simply the lowest of the 3 permissions_s bits: | ||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | ▶ | sub sticky { !!(shift->[2] & 01000) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sticky: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 80 | ▶ | sub filetype { (shift->[2] & 0170000) >> 12 } # 4*3bits | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filetype: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | sub fstype { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fstype: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | Chj::xperlfunc::fstype_for_device($s->dev) | |||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | 80 | our $has_no_subdirs_safe_fstype = +{ | |||||||||||||||||||||||||||||||||||||||||
| 840 | ext2 => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 841 | ext3 => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 842 | ext4 => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 843 | tmpfs => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 844 | vfat => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 845 | squashfs => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 846 | overlay => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 847 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | ▶ | sub has_no_subdirs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_no_subdirs: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | $s->is_dir or die "has_no_subdirs can only be used on directories"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | my $dev = $s->dev; | |||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | my $fstype = $s->fstype; | |||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | ▶ | if ($$has_no_subdirs_safe_fstype{$fstype}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | my $n = $s->nlink; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | $n < 2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | ? die | ||||||||||||||||||||||||||||||||||||||||||
| 858 | "bug: dir on device node $dev has < 2 links, need to ignore this file system" | ||||||||||||||||||||||||||||||||||||||||||
| 859 | : $n == 2; | ||||||||||||||||||||||||||||||||||||||||||
| 860 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 861 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | # Guess access rights from permission bits | ||||||||||||||||||||||||||||||||||||||||||
| 866 | # note that these might guess wrong (because of chattr stuff, | ||||||||||||||||||||||||||||||||||||||||||
| 867 | # or things like grsecurity,lids,selinux..)! | ||||||||||||||||||||||||||||||||||||||||||
| 868 | # Also NOTE: this does not check parent folders of this item! | ||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | ▶ | sub checkaccess_for_submask_by_uid_gids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkaccess_for_submask_by_uid_gids: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | my ($mod, $uid, $gids) = @_; # the latter being an array ref! | |||||||||||||||||||||||||||||||||||||||||
| 872 | #return 1 if $uid == 0; | ||||||||||||||||||||||||||||||||||||||||||
| 873 | # ^ this is not correct for say, is_executable with uid 0; | ||||||||||||||||||||||||||||||||||||||||||
| 874 | # XXX how should it behave in other cases? | ||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | ▶ | if ($s->[4] == $uid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | return !!($s->[2] & (00100 * $mod)) | |||||||||||||||||||||||||||||||||||||||||
| 877 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | ▶ | if ($gids) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | for my $gid (@$gids) { | |||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | ▶ | length($gid) == length($gid +0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | or Carp::croak "invalid gid argument '$gid' - maybe " | ||||||||||||||||||||||||||||||||||||||||||
| 882 | . " you forgot to split '\$)'?"; | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | # XXX: what if one is member of group 0, is this special? | ||||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | ▶ | if ($s->[5] == $gid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | ▶ | if ($s->[2] & (00010 * $mod)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 888 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||
| 890 | # even if others are allowed, we are not | ||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | return !!($s->[2] & (00001 * $mod)) | |||||||||||||||||||||||||||||||||||||||||
| 896 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | Carp::croak "missing gids argument - might just be a ref to " | |||||||||||||||||||||||||||||||||||||||||
| 898 | . "an empty array"; | ||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | ▶ | sub readable_by_uid_gids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readable_by_uid_gids: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | splice @_, 1, 0, 4; | |||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | goto &checkaccess_for_submask_by_uid_gids; | |||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | ▶ | sub writeable_by_uid_gids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeable_by_uid_gids: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | splice @_, 1, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | goto &checkaccess_for_submask_by_uid_gids; | |||||||||||||||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||||||||||||||||
| 912 | 80 | *writable_by_uid_gids = \&writeable_by_uid_gids; | |||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | ▶ | sub executable_by_uid_gids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
executable_by_uid_gids: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | splice @_, 1, 0, 1; | |||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | goto &checkaccess_for_submask_by_uid_gids; | |||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | ▶ | sub Filetype_is_file { shift == 8 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | ▶ | sub is_file { Filetype_is_file(shift->filetype) } # call it is_normalfile ? | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | ▶ | sub Filetype_is_dir { shift == 4 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_dir: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | sub is_dir { Filetype_is_dir(shift->filetype) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_dir: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 923 | 80 | ▶ | sub Filetype_is_link { shift == 10 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_link: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 924 | 80 | ▶ | sub is_link { Filetype_is_link(shift->filetype) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_link: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 925 | 80 | *is_symlink = \&is_link; | |||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | ▶ | sub Filetype_is_socket { shift == 12 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_socket: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | ▶ | sub is_socket { Filetype_is_socket(shift->filetype) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_socket: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | ▶ | sub Filetype_is_chardevice { shift == 2 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_chardevice: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | sub is_chardevice { Filetype_is_chardevice(shift->filetype) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_chardevice: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | sub Filetype_is_blockdevice { shift == 6 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_blockdevice: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | ▶ | sub is_blockdevice { Filetype_is_blockdevice(shift->filetype) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_blockdevice: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | ▶ | sub Filetype_is_pipe { shift == 1 } # or call it is_fifo? | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Filetype_is_pipe: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | ▶ | sub is_pipe { Filetype_is_pipe(shift->filetype) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_pipe: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||
| 935 | # (See NOTE on checkaccess_for_submask_by_uid_gids!) | ||||||||||||||||||||||||||||||||||||||||||
| 936 | 0 | ▶ | sub is_executable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_executable: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 937 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | my ($maybe_allow_dirs, $maybe_uid, $maybe_gids) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | ▶ | my $allow_dirs = $maybe_allow_dirs // 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$maybe_allow_dirs // 1
MC/DC0%0/1
$maybe_allow_dirs // 1
$maybe_allow_dirs
Truth table0%0/2
A
A= $maybe_allow_dirs
| |||||||||||||||||||||||||||||||||||||||||||
| 941 | 0 | ▶ | my $uid = $maybe_uid // $>; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$maybe_uid // $>
MC/DC0%0/2
$maybe_uid // $>
$maybe_uid
$>
Truth table0%0/3
A // B
A= $maybe_uidB= $>
| |||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | ▶ | my $gids = $maybe_gids // [split / /, $)]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$maybe_gids // [split(/ /, $), 0)]
MC/DC0%0/1
$maybe_gids // [split(/ /, $), 0)]
$maybe_gids
Truth table0%0/2
A
A= $maybe_gids
| |||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | ▶ | (($s->is_file or ($allow_dirs and $s->is_dir)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$s->is_file or $allow_dirs and $s->is_dir
$allow_dirs and $s->is_dir
MC/DC0%0/3
$s->is_file or $allow_dirs and $s->is_dir
$s->is_file
$allow_dirs
$s->is_dir
Truth table0%0/4
A or B and C
A= $s->is_fileB= $allow_dirsC= $s->is_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 945 | and $s->executable_by_uid_gids($uid, $gids)) | ||||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | sub type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | ▶ | if ($s->is_dir) {"dir"} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | elsif ($s->is_link) {"link"} | |||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | elsif ($s->is_file) {"file"} | |||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | elsif ($s->is_socket) {"socket"} | |||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | elsif ($s->is_chardevice) {"chardevice"} | |||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | elsif ($s->is_blockdevice) {"blockdevice"} | |||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | elsif ($s->is_pipe) {"pipe"} | |||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | else { die "unknown type of filetype: " . $s->filetype } | |||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||
| 960 | # check whether "a file has changed" | ||||||||||||||||||||||||||||||||||||||||||
| 961 | 0 | ▶ | sub equal_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal_content: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 963 | 0 | my ($s2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | ▶ | ( $s->dev == $s2->dev | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$s->dev == $s2->dev and $s->ino == $s2->ino and $s->size == $s2->size
$s->dev == $s2->dev and $s->ino == $s2->ino
MC/DC0%0/3
$s->dev == $s2->dev and $s->ino == $s2->ino and $s->size == $s2->size
$s->dev == $s2->dev
$s->ino == $s2->ino
$s->size == $s2->size
Truth table0%0/4
A and B and C
A= $s->dev == $s2->devB= $s->ino == $s2->inoC= $s->size == $s2->size
| |||||||||||||||||||||||||||||||||||||||||||
| 965 | and $s->ino == $s2->ino | ||||||||||||||||||||||||||||||||||||||||||
| 966 | and $s->size == $s2->size | ||||||||||||||||||||||||||||||||||||||||||
| 967 | and $s->mtime == $s2->mtime) | ||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||
| 970 | # Could also implement FP::Abstract::Equal, but do not just use | ||||||||||||||||||||||||||||||||||||||||||
| 971 | # the following *equal for it, rather check *all* the fields! | ||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | ▶ | sub equal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | my ($s2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||
| 976 | # permissions: | ||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | ( $s->equal_content($s2) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$s->equal_content($s2) and $s->mode == $s2->mode and $s->uid == $s2->uid
$s->equal_content($s2) and $s->mode == $s2->mode
MC/DC0%0/3
$s->equal_content($s2) and $s->mode == $s2->mode and $s->uid == $s2->uid
$s->equal_content($s2)
$s->mode == $s2->mode
$s->uid == $s2->uid
Truth table0%0/4
A and B and C
A= $s->equal_content($s2)B= $s->mode == $s2->modeC= $s->uid == $s2->uid
| |||||||||||||||||||||||||||||||||||||||||||
| 978 | and $s->mode == $s2->mode | ||||||||||||||||||||||||||||||||||||||||||
| 979 | and $s->uid == $s2->uid | ||||||||||||||||||||||||||||||||||||||||||
| 980 | and $s->gid == $s2->gid) | ||||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | ▶ | sub same_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
same_node: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | my ($s2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | ▶ | ($s->ino == $s2->ino and $s->dev == $s2->dev) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||
| 989 | # for simplicity (and in cases where I copy values in 'rows' (lists of methods)): | ||||||||||||||||||||||||||||||||||||||||||
| 990 | # ATTENTION: these are non-caching! see below. | ||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | ▶ | sub username { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
username: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | scalar $s->getpw | |||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | ▶ | sub groupname { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
groupname: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | scalar $s->getgr | |||||||||||||||||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||
| 1001 | # note that those are sensitive to list context!: | ||||||||||||||||||||||||||||||||||||||||||
| 1002 | # (and yes those should 'probably' return such objects as these, too..) | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | ▶ | sub getpw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getpw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | getpwuid($s->uid) | |||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||
| 1008 | 0 | ▶ | sub getgr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getgr: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | getgrgid($s->gid) | |||||||||||||||||||||||||||||||||||||||||
| 1011 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | # for performance: | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | ▶ | sub caching_getpw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
caching_getpw: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | Chj::xperlfunc::caching_getpwuid($s->uid); | |||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | ▶ | sub caching_getgr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
caching_getgr: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | Chj::xperlfunc::caching_getgrgid($s->gid); | |||||||||||||||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | sub caching_username { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
caching_username: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | scalar $s->caching_getpw | |||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | ▶ | sub caching_groupname { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
caching_groupname: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1030 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | scalar $s->caching_getgr | |||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 80 | ▶ | use FP::Div qw(min max); # min just for the backwards-compatible | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1036 | # re-export | ||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||
| 1038 | 80 | package Chj::xperlfunc::mtimed { | |||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | ▶ | sub path { shift->[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1041 | 80 | ▶ | sub mtime { shift->[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mtime: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | sub lstat { shift->[2] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lstat: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | ▶ | sub maybe_stat { shift->[3] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maybe_stat: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||
| 1045 | # --- | ||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | ▶ | sub xstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xstat: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | $$s[3] || die "Xstat gave file not found for: '$$s[0]'"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | sub is_link { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_link: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | shift->[2]->is_link | |||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | ▶ | sub is_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_dir: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | ▶ | $s->is_link ? $s->xstat->is_dir : $s->lstat->is_dir | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | ▶ | sub is_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_file: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | ▶ | $s->is_link ? $s->xstat->is_file : $s->lstat->is_file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||
| 1066 | 96 | ▶ | sub XLmtimed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
XLmtimed: called CC=5 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1067 | 96 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1068 | 96 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1069 | 96 | ▶ | if (my $ls = Xlstat $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1070 | 80 | bless do { | |||||||||||||||||||||||||||||||||||||||||
| 1071 | 80 | ▶ | if ($ls->is_link) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1072 | 0 | ▶ | if (my $s = Xstat $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | [$path, max($ls->mtime, $s->mtime), $ls, $s] | |||||||||||||||||||||||||||||||||||||||||
| 1074 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | [$path, $ls->mtime, $ls, undef] | |||||||||||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | 80 | [$path, $ls->mtime, $ls, undef] | |||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | }, "Chj::xperlfunc::mtimed" | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | 16 | } | |||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||
| 1086 | 48 | ▶ | sub xLmtimed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xLmtimed: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1087 | 48 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | 48 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1089 | 48 | my $t = XLmtimed $path; | |||||||||||||||||||||||||||||||||||||||||
| 1090 | 48 | ▶ | (defined $t) ? $t : die "xLmtimed: '$path': $!" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||
| 1093 | 48 | ▶ | sub xLmtime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xLmtime: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1094 | 48 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1095 | 48 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1096 | 48 | xLmtimed($path)->mtime | |||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 48 | ▶ | sub XLmtime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
XLmtime: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1100 | 48 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1101 | 48 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1102 | 48 | ▶ | if (defined(my $s = XLmtimed($path))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1103 | 32 | $s->mtime | |||||||||||||||||||||||||||||||||||||||||
| 1104 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | 16 | } | |||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||
| 1109 | 80 | package Chj::xperlfunc::xlocaltime { | |||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||
| 1111 | 0 | ▶ | sub sec { shift->[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sec: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1112 | 0 | ▶ | sub min { shift->[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1113 | 0 | ▶ | sub hour { shift->[2] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hour: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1114 | 80 | ▶ | sub mday { shift->[3] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mday: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | ▶ | sub mon { shift->[4] } # 0..11 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mon: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ▶ | sub year { shift->[5] } # -1900 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
year: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1117 | 0 | ▶ | sub wday { shift->[6] } # 0=sunday | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wday: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1118 | 80 | ▶ | sub yday { shift->[7] } # 0..36[45] | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
yday: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | ▶ | sub isdst { shift->[8] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isdst: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1120 | 160 | ▶ | sub Year { shift->[5] + 1900 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Year: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1121 | 80 | ▶ | sub Mon { shift->[4] + 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Mon: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | ▶ | sub Wday { shift->[6] + 1 } # 1=sunday | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Wday: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1123 | 160 | ▶ | sub wDay { my $d = shift->[6]; $d == 0 ? 6 : $d - 1 } # 0=monday | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wDay: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | ▶ | sub set_sec { my ($s, $v) = @_; $s->[0] = $v; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_sec: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | ▶ | sub set_min { my ($s, $v) = @_; $s->[1] = $v; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_min: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | ▶ | sub set_hour { my ($s, $v) = @_; $s->[2] = $v; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_hour: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | ▶ | sub set_mday { my ($s, $v) = @_; $s->[3] = $v; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_mday: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | ▶ | sub set_mon { my ($s, $v) = @_; $s->[4] = $v; $s } # 0..11 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_mon: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | ▶ | sub set_year { my ($s, $v) = @_; $s->[5] = $v; $s } # -1900 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_year: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1131 | #sub set_wday { my ($s,$v) = @_; $s->[6] = $v; $s } # 0=sunday | ||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | ▶ | sub set_yday { my ($s, $v) = @_; $s->[7] = $v; $s } # 0..36[45] | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_yday: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | ▶ | sub set_isdst { my ($s, $v) = @_; $s->[8] = $v; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_isdst: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1134 | 0 | ▶ | sub set_Year { my ($s, $v) = @_; $s->[5] = $v - 1900; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_Year: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | ▶ | sub set_Mon { my ($s, $v) = @_; $s->[4] = $v - 1; $s } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_Mon: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||
| 1137 | #sub set_Wday | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | #sub set_wDay | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | # but those don't have any effect on timelocal anyway. | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||
| 1141 | 0 | ▶ | sub unixtime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unixtime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | Time::Local::timelocal(@$s) | |||||||||||||||||||||||||||||||||||||||||
| 1144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||
| 1146 | 80 | ▶ | sub iso_week_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iso_week_number: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1147 | 80 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||
| 1149 | # On which yday does week 01 start for `Year`? | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||||||||||||||||
| 1151 | 80 | my $wDay = $s->wDay; | |||||||||||||||||||||||||||||||||||||||||
| 1152 | 80 | my $yday = $s->yday; | |||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | 80 | my $weekstart_day = $yday - $wDay; | |||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||
| 1156 | 80 | my ($offset, $weeks) = ($weekstart_day % 7, int($weekstart_day / 7)); | |||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||
| 1158 | 80 | ▶ | my $week = ($offset >= 4) ? $weeks + 2 : $weeks + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1159 | 80 | ▶ | $yday < $offset ? "LASTYEAR" : $week | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||
| 1161 | # XX needs to give the year, actually! Buggy. | ||||||||||||||||||||||||||||||||||||||||||
| 1162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||
| 1164 | 80 | ▶ | sub Year_and_iso_week_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Year_and_iso_week_number: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1165 | 80 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1166 | 80 | $s->Year . "-W" . $s->iso_week_number | |||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||
| 1168 | # XX needs to give the year with the week, actually! Buggy. | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||
| 1172 | 80 | ▶ | sub xlocaltime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlocaltime: called CC=4 SCAR=16.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1173 | 80 | ▶ | @_ >= 0 and @_ <= 1 or fp_croak_arity "0-1"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ >= 0 and @_ <= 1
MC/DC0%0/2
@_ >= 0 and @_ <= 1
@_ >= 0
@_ <= 1
Truth table33%1/3
A and B
A= @_ >= 0B= @_ <= 1
| |||||||||||||||||||||||||||||||||||||||||||
| 1174 | 80 | ▶ | bless [localtime(defined $_[0] ? $_[0] : time)], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1175 | "Chj::xperlfunc::xlocaltime" | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | ▶ | sub xreadlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadlink: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | ▶ | my $res | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1180 | = @_ == 0 ? readlink | ||||||||||||||||||||||||||||||||||||||||||
| 1181 | : @_ == 1 ? readlink $_[0] | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | : croak "xreadlink: wrong number of arguments"; | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | ▶ | defined $res or croak @_ ? "xreadlink @_: $!" : "xreadlink: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | $res | |||||||||||||||||||||||||||||||||||||||||
| 1185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | ▶ | sub xmkdir_with_paragon { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmkdir_with_paragon: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | ▶ | @_ == 2 or @_ == 3 or fp_croak_arity "2 or 3"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 2 or @_ == 3
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 1189 | 0 | warn "UNTESTED!"; | |||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | my ($owner, $group, $mode) = (xstat $_[1])[4, 5, 2]; | |||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | xmkdir $_[0], 0; | |||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | ▶ | if (!chown $owner, $group, $_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | ▶ | $_[2] and croak "xmvmkdir: could not recreate user or group: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | xchmod $mode, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||
| 1198 | 80 | package Chj::xperlfunc::tmpdir { | |||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | local ($@, $!); | |||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | ▶ | rmdir $$self ## hack | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1204 | and warn "removed tmpdir '$$self'"; ## should it warn? prolly not. | ||||||||||||||||||||||||||||||||||||||||||
| 1205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | ▶ | sub xtmpdir_with_paragon { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xtmpdir_with_paragon: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | ▶ | @_ == 1 or @_ == 2 or fp_croak_arity "1 or 2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 or @_ == 2
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1
@_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | my ($paragon, $strict) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1211 | 0 | my ($owner, $group, $mode) = (xstat $paragon)[4, 5, 2]; | |||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | my $newname; | |||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | TRY: for (0 .. 2) { | |||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | $newname = $paragon; | |||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | $newname =~ s{(^|/)([^/]+)\z}{"$1.$2.tmp".int(rand(100000))}se; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | 0 | ▶ | last TRY if mkdir $newname, 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | ▶ | if ($! != EEXIST) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | croak "xtmpdir_with_paragon: mkdir: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | 0 | ▶ | if (!chown $owner, $group, $newname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | ▶ | if ($strict) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1223 | 0 | rmdir $newname; | |||||||||||||||||||||||||||||||||||||||||
| 1224 | 0 | croak "xtmpdir_with_paragon: could not recreate user or group: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | ▶ | if (!chmod $mode, $newname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1228 | 0 | rmdir $newname; | |||||||||||||||||||||||||||||||||||||||||
| 1229 | 0 | croak "xtmpdir_with_paragon: chmod: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | return bless \$newname, 'Chj::xperlfunc::tmpdir'; | |||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||
| 1233 | # ^ so that it will be removed upon error | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||
| 1236 | 0 | ▶ | sub xmvmkdir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmvmkdir: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1237 | 0 | ▶ | @_ == 2 or @_ == 3 or fp_croak_arity "2 or 3"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 2 or @_ == 3
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 1238 | 0 | xrename $_[0], $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 1239 | 0 | my ($owner, $group, $mode) = (xstat $_[1])[4, 5, 2]; | |||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | xmkdir $_[0], 0; | |||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | ▶ | if (!chown $owner, $group, $_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | ▶ | $_[2] and croak "xmvmkdir: could not recreate user or group: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | xchmod $mode, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||
| 1247 | 0 | ▶ | sub xunlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xunlink: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1248 | 0 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 1249 | 0 | ▶ | unlink $_ or croak "xunlink '$_': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||
| 1253 | 0 | ▶ | sub xlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlink: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1255 | 0 | ▶ | link $_[0], $_[1] or croak "xlink '$_[0]','$_[1]': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||
| 1258 | 0 | ▶ | sub xsymlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsymlink: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1260 | 0 | ▶ | symlink $_[0], $_[1] or croak "xsymlink to '$_[1]': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||
| 1263 | 0 | ▶ | sub xutime { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xutime: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | ▶ | @_ >= 2 or fp_croak_arity ">= 2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | my ($atime, $mtime) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 1266 | 0 | ▶ | utime $atime, $mtime, @_ or croak "xutime @_: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||
| 1269 | 0 | ▶ | sub xkill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xkill: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1270 | 0 | my $sig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | ▶ | kill $sig, @_ or croak "xkill $sig @_: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | ▶ | sub xchroot { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xchroot: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1275 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1276 | 0 | my ($rtd) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | ▶ | chroot $rtd or die "could not chroot to '$rtd': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1279 | |||||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | ▶ | sub xeval { # meant for string eval only, of course. | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xeval: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | ▶ | @_ == 1 or die "wrong number of arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1282 | ## hm ps should one localize $@ here? | ||||||||||||||||||||||||||||||||||||||||||
| 1283 | 0 | my $wantarray = wantarray; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | ▶ | if (defined $wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | ▶ | if ($wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1286 | 0 | my @res = eval $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | ▶ | if (ref $@ or $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $@ or $@
MC/DC0%0/2
ref $@ or $@
ref $@
$@
Truth table0%0/3
A or B
A= ref $@B= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | die $@ | |||||||||||||||||||||||||||||||||||||||||
| 1289 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1290 | @res | ||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 1292 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1293 | 0 | my $res = eval $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1294 | 0 | ▶ | if (ref $@ or $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $@ or $@
MC/DC0%0/2
ref $@ or $@
ref $@
$@
Truth table0%0/3
A or B
A= ref $@B= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 1295 | 0 | die $@ | |||||||||||||||||||||||||||||||||||||||||
| 1296 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | 0 | $res | |||||||||||||||||||||||||||||||||||||||||
| 1298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1301 | 0 | eval $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1302 | 0 | ▶ | if (ref $@ or $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $@ or $@
MC/DC0%0/2
ref $@ or $@
ref $@
$@
Truth table0%0/3
A or B
A= ref $@B= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 1303 | 0 | die $@ | |||||||||||||||||||||||||||||||||||||||||
| 1304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | ▶ | sub xfileno { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xfileno: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1309 | |||||||||||||||||||||||||||||||||||||||||||
| 1310 | # takes fh or integer | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | 0 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1312 | 0 | my $fd = fileno $arg; | |||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | ▶ | return $fd if defined $fd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | ▶ | return $arg +0 if $arg =~ /^\s*\d+\s*\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1315 | 0 | croak "xfileno: '$arg' is not a filehandle nor a file descriptor number"; | |||||||||||||||||||||||||||||||||||||||||
| 1316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||||||||||||||||
| 1318 | 0 | ▶ | sub xsysread { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsysread: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1319 | 0 | ▶ | @_ >= 3 and @_ <= 4 or fp_croak_arity "3-4"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ >= 3 and @_ <= 4
MC/DC0%0/2
@_ >= 3 and @_ <= 4
@_ >= 3
@_ <= 4
Truth table0%0/3
A and B
A= @_ >= 3B= @_ <= 4
| |||||||||||||||||||||||||||||||||||||||||||
| 1320 | 0 | my $rv = do { | |||||||||||||||||||||||||||||||||||||||||
| 1321 | 0 | ▶ | if (@_ == 4) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | sysread $_[0], $_[1], $_[2], $_[3] | |||||||||||||||||||||||||||||||||||||||||
| 1323 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | sysread $_[0], $_[1], $_[2] | |||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | ▶ | defined $rv or die "xsysread(" . singlequote_many(@_) . "): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1328 | 0 | $rv | |||||||||||||||||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||
| 1331 | # ^- ok this is silly (is it?) since I've got Chj::IO::File. But that | ||||||||||||||||||||||||||||||||||||||||||
| 1332 | # latter one is not yet complete, I'm debugging xreadline atm. | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||
| 1334 | 80 | ▶ | use FP::Show qw(show_many); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||
| 1336 | 18 | ▶ | sub basename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
basename: called CC=13 SCAR=38.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1337 | 18 | ▶ | @_ >= 1 and @_ <= 3 or fp_croak_arity "1-3"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ >= 1 and @_ <= 3
MC/DC0%0/2
@_ >= 1 and @_ <= 3
@_ >= 1
@_ <= 3
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 3
| |||||||||||||||||||||||||||||||||||||||||||
| 1338 | 18 | my ($path, $maybe_suffixS, $insensitive) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1339 | 18 | my $copy = $path; | |||||||||||||||||||||||||||||||||||||||||
| 1340 | 18 | $copy =~ s|.*/||s; | |||||||||||||||||||||||||||||||||||||||||
| 1341 | 18 | my $res = do { | |||||||||||||||||||||||||||||||||||||||||
| 1342 | 18 | ▶ | length($copy) ? $copy : do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||
| 1344 | # path ending in slash--or empty from the start. | ||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | ▶ | if ($path =~ s|/+\z||s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1346 | 0 | $path =~ s|.*/||s; | |||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||
| 1348 | # ^ this is necessary since we did it on $copy only, | ||||||||||||||||||||||||||||||||||||||||||
| 1349 | # before! | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | ▶ | if (length $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1351 | 0 | $path | |||||||||||||||||||||||||||||||||||||||||
| 1352 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1353 | 0 | "/" # or die? no. | |||||||||||||||||||||||||||||||||||||||||
| 1354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1356 | 0 | croak "basename(" | |||||||||||||||||||||||||||||||||||||||||
| 1357 | . show_many(@_) . "): " | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | . "cannot get basename from empty string"; | ||||||||||||||||||||||||||||||||||||||||||
| 1359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1362 | 18 | ▶ | if (defined $maybe_suffixS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1363 | 6 | ▶ | if (ref($maybe_suffixS)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1364 | TRY: { | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | 0 | for my $suffix (@$maybe_suffixS) { | |||||||||||||||||||||||||||||||||||||||||
| 1366 | 0 | ▶ | ( $insensitive | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1367 | ? $res =~ s/\Q$suffix\E\z//i | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | : $res =~ s/\Q$suffix\E\z//) | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | and last TRY; | ||||||||||||||||||||||||||||||||||||||||||
| 1370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | 0 | croak "basename(" . show_many(@_) . "): " . "no suffix matches"; | |||||||||||||||||||||||||||||||||||||||||
| 1372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1373 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1374 | 6 | ▶ | ( $insensitive | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1375 | ? $res =~ s/\Q$maybe_suffixS\E\z//i | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | : $res =~ s/\Q$maybe_suffixS\E\z//) | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | or croak "basename(" | ||||||||||||||||||||||||||||||||||||||||||
| 1378 | . show_many(@_) . "): " | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | . "suffix does not match"; | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | $res | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | 18 | } | |||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||
| 1385 | # main> :d basename "/fun/." | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | # $VAR1 = '.'; | ||||||||||||||||||||||||||||||||||||||||||
| 1387 | # but the shell util acts the same way. | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | |||||||||||||||||||||||||||||||||||||||||||
| 1389 | #chris@novo:~$ basename foo/bar/cj.git/blabla .git/blabla | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | #blabla | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | # so no, do not strip before basenaming, really do it afterwards as I do | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 30 | ▶ | sub dirname { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dirname: called CC=7 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1394 | 30 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1395 | 30 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1396 | 30 | ▶ | if ($path =~ s|/+[^/]+/*\z||) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1397 | 27 | ▶ | if (length $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1398 | 27 | $path | |||||||||||||||||||||||||||||||||||||||||
| 1399 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | 0 | "/" | |||||||||||||||||||||||||||||||||||||||||
| 1401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||
| 1404 | # deviates from the shell in that dirname of . and / are errors. good? | ||||||||||||||||||||||||||||||||||||||||||
| 1405 | 3 | ▶ | if ($path =~ m|^/+\z|) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1406 | 0 | die "can't go out of file system" | |||||||||||||||||||||||||||||||||||||||||
| 1407 | } elsif ($path eq ".") { | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | 0 | die "can't go above cur dir in a relative path"; | |||||||||||||||||||||||||||||||||||||||||
| 1409 | } elsif ($path eq "") { | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | die "can't take dirname of empty string"; | |||||||||||||||||||||||||||||||||||||||||
| 1411 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | 3 | "." | |||||||||||||||||||||||||||||||||||||||||
| 1413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||||||||||||||||
| 1417 | sub xmkdir_p; | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||
| 1419 | 18 | ▶ | sub xmkdir_p { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmkdir_p: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1420 | 18 | ▶ | @_ == 1 or @_ == 2 or fp_croak_arity "1 or 2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 or @_ == 2
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1
@_ == 2
Truth table66%2/3
A or B
A= @_ == 1B= @_ == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 1421 | 18 | my ($path, $maybe_mask) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1422 | 18 | ▶ | my $mask = $maybe_mask // 0777; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$maybe_mask // 511
MC/DC100%1/1
$maybe_mask // 511
$maybe_mask
Truth table100%2/2
A
A= $maybe_mask
| |||||||||||||||||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||||||||||||||||
| 1424 | # (XX: see commit d1abd3c2 in megacopy for possible improvement) | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | 18 | ▶ | if (-d $path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1426 | () | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | 15 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 1428 | 3 | ▶ | if (mkdir $path, $mask) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1429 | () | ||||||||||||||||||||||||||||||||||||||||||
| 1430 | 1 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 1431 | 2 | ▶ | if ($! == ENOENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1432 | 2 | xmkdir_p(dirname($path), $mask); | |||||||||||||||||||||||||||||||||||||||||
| 1433 | 2 | ▶ | mkdir $path, $mask or die "could not mkdir('$path'): $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1434 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1435 | 0 | die "could not mkdir('$path'): $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1440 | |||||||||||||||||||||||||||||||||||||||||||
| 1441 | 0 | ▶ | sub xlink_p { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlink_p: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1442 | 0 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1443 | 0 | my ($from, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1444 | 0 | xmkdir_p(dirname $to); | |||||||||||||||||||||||||||||||||||||||||
| 1445 | 0 | xlink $from, $to | |||||||||||||||||||||||||||||||||||||||||
| 1446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||
| 1448 | # sub xuser_uid { | ||||||||||||||||||||||||||||||||||||||||||
| 1449 | # @_ == 1 or die "wrong number of arguments"; | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | # my ($user) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 1451 | # my ($login,$pass,$uid,$gid) = getpwnam($user) | ||||||||||||||||||||||||||||||||||||||||||
| 1452 | # or die "xuser_uid: '$user' not in passwd file"; | ||||||||||||||||||||||||||||||||||||||||||
| 1453 | # $uid | ||||||||||||||||||||||||||||||||||||||||||
| 1454 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | 80 | package Chj::xperlfunc::Getpwnam { | |||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||
| 1457 | 80 | ▶ | use Chj::Class::Array -fields => -publica => | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1458 | 80 | qw(name passwd uid gid quota comment gcos dir shell expire); | |||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||
| 1460 | 0 | ▶ | sub perhaps_get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perhaps_get: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1461 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1462 | 0 | my ($user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1463 | 0 | my $s = bless [getpwnam($user)], $class; | |||||||||||||||||||||||||||||||||||||||||
| 1464 | 0 | ▶ | if (@$s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1465 | 0 | ▶ | wantarray ? @$s : $s ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1466 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | return | ||||||||||||||||||||||||||||||||||||||||||
| 1468 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 1469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1470 | 80 | end Chj::Class::Array; | |||||||||||||||||||||||||||||||||||||||||
| 1471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1472 | |||||||||||||||||||||||||||||||||||||||||||
| 1473 | 0 | ▶ | sub xgetpwnam { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xgetpwnam: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1474 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1475 | 0 | my ($user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1476 | 0 | ▶ | if (wantarray) { ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1477 | 0 | my @f = Chj::xperlfunc::Getpwnam->perhaps_get($user); | |||||||||||||||||||||||||||||||||||||||||
| 1478 | 0 | ▶ | @f or croak "xgetpwnam: '$user' not in passwd file"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1479 | @f | ||||||||||||||||||||||||||||||||||||||||||
| 1480 | 0 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 1481 | 0 | ▶ | Chj::xperlfunc::Getpwnam->perhaps_get($user) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1482 | or croak "xgetpwnam: '$user' not in passwd file"; | ||||||||||||||||||||||||||||||||||||||||||
| 1483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||||||||||||||||
| 1486 | 80 | package Chj::xperlfunc::Getgrnam { | |||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||
| 1488 | 80 | ▶ | use Chj::Class::Array -fields => -publica => qw(name passwd gid members); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||||||||||||||||
| 1490 | 0 | ▶ | sub perhaps_get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perhaps_get: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1491 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1492 | 0 | my ($user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1493 | 0 | my $s = bless [getgrnam($user)], $class; | |||||||||||||||||||||||||||||||||||||||||
| 1494 | 0 | ▶ | if (@$s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1495 | 0 | ▶ | wantarray ? @$s : $s ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1496 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | return | ||||||||||||||||||||||||||||||||||||||||||
| 1498 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 1499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1500 | 80 | end Chj::Class::Array; | |||||||||||||||||||||||||||||||||||||||||
| 1501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1502 | |||||||||||||||||||||||||||||||||||||||||||
| 1503 | 0 | ▶ | sub xgetgrnam { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xgetgrnam: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1504 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1505 | 0 | my ($group) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1506 | 0 | ▶ | if (wantarray) { ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1507 | 0 | my @f = Chj::xperlfunc::Getgrnam->perhaps_get($group); | |||||||||||||||||||||||||||||||||||||||||
| 1508 | 0 | ▶ | @f or croak "xgetgrnam: '$group' not in group file"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1509 | @f | ||||||||||||||||||||||||||||||||||||||||||
| 1510 | 0 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 1511 | 0 | ▶ | Chj::xperlfunc::Getgrnam->perhaps_get($group) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1512 | or croak "xgetgrnam: '$group' not in group file"; | ||||||||||||||||||||||||||||||||||||||||||
| 1513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||||||||||||||||
| 1516 | # Also see xprint and xprintln methods in Chj::IO::File. | ||||||||||||||||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||||||||||||||||
| 1518 | 80 | ▶ | use Chj::BuiltinTypePredicates 'is_filehandle'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||
| 1520 | 289 | ▶ | sub xprint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xprint: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1521 | 289 | ▶ | my $fh = is_filehandle($_[0]) ? shift : *STDOUT{IO}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1522 | 289 | ▶ | print $fh @_ or die "printing to $fh: $!" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1524 | |||||||||||||||||||||||||||||||||||||||||||
| 1525 | 5 | ▶ | sub xprintln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xprintln: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1526 | 5 | ▶ | my $fh = is_filehandle($_[0]) ? shift : *STDOUT{IO}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1527 | 5 | ▶ | print $fh @_, "\n" or die "printing to $fh: $!" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||
| 1530 | 27 | ▶ | sub _getfile_utf8 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getfile_utf8: called CC=7 SCAR=25.3
| |||||||||||||||||||||||||||||||||||||||||||
| 1531 | 27 | my ($path, $do_throw, $myname) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||||||||||||||||
| 1533 | # using PerlIO::utf8_strict | ||||||||||||||||||||||||||||||||||||||||||
| 1534 | 27 | ▶ | open my $in, '<:utf8_strict', $path or do { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1535 | 0 | ▶ | if ($do_throw or $! != ENOENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$do_throw or $! != 2
MC/DC0%0/2
$do_throw or $! != 2
$do_throw
$! != 2
Truth table0%0/3
A or B
A= $do_throwB= $! != 2
| |||||||||||||||||||||||||||||||||||||||||||
| 1536 | 0 | die "$myname($path): open: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1537 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 1539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1540 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | 27 | my $cnt; | |||||||||||||||||||||||||||||||||||||||||
| 1542 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 1543 | 27 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 1544 | 27 | ▶ | $cnt = <$in> // die "read: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
readline $in // die("read: $!")
MC/DC0%0/1
readline $in // die("read: $!")
readline $in
Truth table50%1/2
A
A= readline $in
| |||||||||||||||||||||||||||||||||||||||||||
| 1545 | 27 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 1546 | 27 | ▶ | } || do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1547 | 0 | my $e = $@; | |||||||||||||||||||||||||||||||||||||||||
| 1548 | 0 | close $in; | |||||||||||||||||||||||||||||||||||||||||
| 1549 | 0 | die "$myname($path): $e" | |||||||||||||||||||||||||||||||||||||||||
| 1550 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1551 | 27 | ▶ | close $in or die "$myname($path): close: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1552 | 27 | $cnt | |||||||||||||||||||||||||||||||||||||||||
| 1553 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1554 | |||||||||||||||||||||||||||||||||||||||||||
| 1555 | 27 | ▶ | sub xgetfile_utf8 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xgetfile_utf8: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1556 | 27 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1557 | 27 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1558 | 27 | _getfile_utf8($path, 1, "xgetfile_utf8") | |||||||||||||||||||||||||||||||||||||||||
| 1559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||
| 1561 | # Return undef if the file does not exist, throw errors for other | ||||||||||||||||||||||||||||||||||||||||||
| 1562 | # issues. | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | 0 | ▶ | sub maybe_getfile_utf8 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maybe_getfile_utf8: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1564 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1565 | 0 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1566 | 0 | _getfile_utf8($path, 0, "maybe_getfile_utf8") | |||||||||||||||||||||||||||||||||||||||||
| 1567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1568 | |||||||||||||||||||||||||||||||||||||||||||
| 1569 | sub xslurp; | ||||||||||||||||||||||||||||||||||||||||||
| 1570 | 80 | *xslurp = \&xgetfile_utf8; | |||||||||||||||||||||||||||||||||||||||||
| 1571 | |||||||||||||||||||||||||||||||||||||||||||
| 1572 | 80 | 1; | |||||||||||||||||||||||||||||||||||||||||