| 1 | package App::Greple::md::Image; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # The files of the images of a Markdown file. They are shown by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Text::ANSI::Image; this module finds them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 221 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 221 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 221 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 221 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 221 | our @EXPORT_OK = qw(local_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 221 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 221 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 221 | ▶ | use Cwd qw(realpath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # The local file of the image of a URL, or undef. Nothing is fetched | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # from the network. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # images/a.png, /path/a.png | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # a path, relative to the directory of the Markdown file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # https://raw.githubusercontent.com/OWNER/REPO/BRANCH/PATH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # https://github.com/OWNER/REPO/blob/BRANCH/PATH (or raw, ?raw=true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # PATH in the work tree of the git repository which has the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Markdown file, when one of its remotes is github.com/OWNER/REPO. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # The README files of CPAN distributions point to their images | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # this way, for MetaCPAN. The branch is not looked at: the file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # is the one in the work tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 24 | ▶ | sub local_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
local_path: called CC=16 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 24 | my($url, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 24 | $dir = File::Spec->rel2abs($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 24 | ▶ | if ($url !~ m{^[a-z][a-z0-9+.-]*:}i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 17 | ▶ | return $url =~ m{^/} ? $url : "$dir/$url"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | ▶ | my($owner, $repo, $rest) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $url =~ m{^https://raw\.githubusercontent\.com/([^/]+)/([^/]+)/(.+)}i ? ($1, $2, $3) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | $url =~ m{^https://github\.com/([^/]+)/([^/]+)/(?:blob|raw)/(.+)}i ? ($1, $2, $3) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | $repo =~ s/\.git$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | $rest =~ s/[?#].*//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | my $top = git_top($dir) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
git_top($dir) // (return)
MC/DC0%0/1
git_top($dir) // (return)
git_top($dir)
Truth table50%1/2
A
A= git_top($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | grep { m{github\.com[:/]\Q$owner\E/\Q$repo\E(?:\.git)?/?$}i } remote_urls($top) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # BRANCH/PATH: the branch may have slashes, so the path is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # longest tail that names a file in the work tree. No part of it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # may go up, and the file must be in the work tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my @part = map { s/%([0-9A-Fa-f]{2})/chr hex $1/ger } split m{/}, $rest, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | return if grep { $_ eq '' or $_ eq '.' or $_ eq '..' or m{/} } @part; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$_ eq '' || $_ eq '.' || $_ eq '..' || m[/]u
$_ eq "" or $_ eq "." or $_ eq ".."
$_ eq "" or $_ eq "."
MC/DC25%1/4
$_ eq '' || $_ eq '.' || $_ eq '..' || m[/]u
$_ eq ""
$_ eq "."
$_ eq ".."
m[/]u
Truth table40%2/5
A or B or C || D
A= $_ eq ""B= $_ eq "."C= $_ eq ".."D= m[/]u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | my $real_top = realpath($top) // return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
realpath($top) // (return)
MC/DC0%0/1
realpath($top) // (return)
realpath($top)
Truth table50%1/2
A
A= realpath($top)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | for my $i (1 .. $#part) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my $path = join '/', $top, @part[$i .. $#part]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | -f $path or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | my $real = realpath($path) // next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
realpath($path) // (next)
MC/DC0%0/1
realpath($path) // (next)
realpath($path)
Truth table50%1/2
A
A= realpath($path)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | return $real if index($real, "$real_top/") == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # The top of the work tree of the git repository which has the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # directory, found by its .git (a directory, or a file in a worktree). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub git_top { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_top: called CC=7 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | state %top; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | $top{$dir} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$top{$dir} //= do {
my $d = $dir;
$d = dirname($d) until -e "$d/.git" or $d eq "/" or $d eq ".";
-e "$d/.git" ? $d : ""
}
MC/DC0%0/2
$top{$dir} //= do {
my $d = $dir;
$d = dirname($d) until -e "$d/.git" or $d eq "/" or $d eq ".";
-e "$d/.git" ? $d : ""
}
$top{$dir}
do {
my $d = $dir;
$d = dirname($d) until -e "$d/.git" or $d eq "/" or $d eq ".";
-e "$d/.git" ? $d : ""
}
Truth table66%2/3
A //= B
A= $top{$dir}B= do {
my $d = $dir;
$d = dirname($d) until -e "$d/.git" or $d eq "/" or $d eq ".";
-e "$d/.git" ? $d : ""
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $d = $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | $d = dirname($d) until -e "$d/.git" or $d eq '/' or $d eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
-e "$d/.git" or $d eq "/" or $d eq "."
-e "$d/.git" or $d eq "/"
MC/DC0%0/3
-e "$d/.git" or $d eq "/" or $d eq "."
-e "$d/.git"
$d eq "/"
$d eq "."
Truth table25%1/4
A or B or C
A= -e "$d/.git"B= $d eq "/"C= $d eq "."
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | -e "$d/.git" ? $d : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | $top{$dir} || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # The URLs of the remotes of a repository, from git itself (no shell). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | ▶ | sub remote_urls { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remote_urls: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | my $top = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | state %urls; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | $urls{$top} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$urls{$top} //= do {
my @u;
if (open my $fh, "-|", "git", "-C", $top, "config", "--get-regexp", "^remote\..*\.url$") {
@u = map({/^\S+\s+(\S+)/u ? $1 : ();} readline $fh);
close $fh;
};
\@u
}
MC/DC0%0/2
$urls{$top} //= do {
my @u;
if (open my $fh, "-|", "git", "-C", $top, "config", "--get-regexp", "^remote\..*\.url$") {
@u = map({/^\S+\s+(\S+)/u ? $1 : ();} readline $fh);
close $fh;
};
\@u
}
$urls{$top}
do {
my @u;
if (open my $fh, "-|", "git", "-C", $top, "config", "--get-regexp", "^remote\..*\.url$") {
@u = map({/^\S+\s+(\S+)/u ? $1 : ();} readline $fh);
close $fh;
};
\@u
}
Truth table66%2/3
A //= B
A= $urls{$top}B= do {
my @u;
if (open my $fh, "-|", "git", "-C", $top, "config", "--get-regexp", "^remote\..*\.url$") {
@u = map({/^\S+\s+(\S+)/u ? $1 : ();} readline $fh);
close $fh;
};
\@u
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my @u; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if (open my $fh, '-|', 'git', '-C', $top, 'config', '--get-regexp', '^remote\..*\.url$') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | @u = map { /^\S+\s+(\S+)/ ? $1 : () } <$fh>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | \@u; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | @{$urls{$top}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 221 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||