| 1 | # | ||||||||||
| 2 | # Copyright (c) 2014-2019 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 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | FunctionalPerl::Htmlgen::PathUtil | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | =head1 NOTE | ||||||||||
| 20 | |||||||||||
| 21 | This is alpha software! Read the status section in the package README | ||||||||||
| 22 | or on the L<website|http://functional-perl.org/>. | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | package FunctionalPerl::Htmlgen::PathUtil; | ||||||||||
| 27 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 3 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 3 | ▶ | use experimental "signatures"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | 3 | ▶ | use Exporter "import"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 3 | our @EXPORT = qw(); | |||||||||
| 35 | 3 | our @EXPORT_OK = qw(path_add path_diff | |||||||||
| 36 | path0 | ||||||||||
| 37 | path_path0_append | ||||||||||
| 38 | ); | ||||||||||
| 39 | 3 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||
| 40 | |||||||||||
| 41 | 3 | ▶ | use FP::Docstring; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | # move to lib | ||||||||||
| 44 | 3 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 3 | ▶ | use FP::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 3 | ▶ | use Chj::xperlfunc qw(dirname); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 3 | ▶ | use Chj::TEST ":all"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | 6 | ▶ | sub path_add ($base, $rel) { | ||||||||
|
Subroutine
path_add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | 6 | __ '($basestr, $relstr) -> $str ' | |||||||||
| 51 | . '-- throws exception if $relstr goes above all of $basestr (via FP::Path)'; | ||||||||||
| 52 | 6 | FP::Path->new_from_string($base)->add(FP::Path->new_from_string($rel), 1) | |||||||||
| 53 | ->string | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | TEST { path_add "/foo", "/zoo" } "/zoo"; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 1 | ▶ | TEST { path_add "/foo", "../zoo" } "/zoo"; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 1 | ▶ | TEST { path_add "/foo", "zoo/loo" } "/foo/zoo/loo"; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 1 | ▶ | TEST { path_add "/foo", "zoo//loo/." } "/foo/zoo/loo/"; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 1 | ▶ | TEST { path_add ".", "zoo/loo" } "zoo/loo"; # definitely | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 1 | ▶ | TEST_EXCEPTION { path_add ".", "../zoo/loo" } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 62 | |||||||||||
| 63 | # "../zoo/loo"; # yes that's something I want, ok? | ||||||||||
| 64 | 3 | "can't take '..' of root directory"; # well, ok? | |||||||||
| 65 | |||||||||||
| 66 | 3 | ▶ | sub path_diff ($path0from, $path0to) { | ||||||||
|
Subroutine
path_diff: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 67 | 3 | __ '($path0from, $path0to) -> $patstr ' | |||||||||
| 68 | . '-- (via File::Spec with Windows hack)'; | ||||||||||
| 69 | 3 | ▶ | my $from = $path0from =~ m|(.*?)/+$|s ? $1 : dirname $path0from; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 3 | my $res = File::Spec->abs2rel($path0to, $from); | |||||||||
| 71 | |||||||||||
| 72 | # XX HACK for Windows (why is this using File::Spec, anyway?): | ||||||||||
| 73 | 3 | $res =~ s{\\}{/}sg; | |||||||||
| 74 | 3 | $res | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 1 | ▶ | TEST { path_diff "foo/", "bar.css" } '../bar.css'; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 78 | 1 | ▶ | TEST { path_diff "foo/bar.html", "bar.css" } '../bar.css'; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 79 | 1 | ▶ | TEST { path_diff "foo", "bar.css" } 'bar.css'; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 80 | |||||||||||
| 81 | #TEST{path_diff ".", "bar.css"} 'bar.css'; | ||||||||||
| 82 | |||||||||||
| 83 | #/lib | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub path0($path) { | ||||||||
|
Subroutine
path0: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 86 | 0 | __ 'delete "(../)*" prefix, just a hacky way to strip path prefix'; | |||||||||
| 87 | 0 | my $path0 = $path; | |||||||||
| 88 | 0 | ▶ | while ($path0 =~ s|^\.\./||) { } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | ▶ | die if $path0 =~ /\.\./; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | $path0 | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 4 | ▶ | sub path_path0_append ($dir, $relpath0) { | ||||||||
|
Subroutine
path_path0_append: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 94 | 4 | __ "a path-append that doesn't result in a leading './'"; | |||||||||
| 95 | 4 | my $p = "$dir/$relpath0"; | |||||||||
| 96 | 4 | $p =~ s|^\./||; | |||||||||
| 97 | 4 | $p | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 3 | 1 | |||||||||