| 1 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | package Zest::Author::TABULO::Util::ShareDir; | ||||||||||||||||||||
| 5 | 2 | our $VERSION = '1.000014'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use File::ShareDir (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use Exporter::Shiny qw( dist_file dist_dir); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | #region: #== UTILITY FUNCTIONS (EXPORT_OK) == | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 4 | ▶ | sub dist_file { | ||||||||||||||||||
|
Subroutine
dist_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 15 | 4 | my $pkg = shift; | |||||||||||||||||||
| 16 | 4 | eval { path( dist_dir($pkg)->child(@_) ) }; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 4 | ▶ | sub dist_dir { | ||||||||||||||||||
|
Subroutine
dist_dir: called CC=11 SCAR=26.0
Pod
undocumented
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | # Code adopted from L<File::Share>, which unfortunately does not work when we are in BUILD dir (blib/lib). | ||||||||||||||||||||
| 22 | 4 | my ($dist) = (@_); | |||||||||||||||||||
| 23 | 4 | $dist =~ s![.]pm$!!; # strip trailing .pm (if any) | |||||||||||||||||||
| 24 | 4 | $dist =~ s!(::|/)!-!g; # e.g. ==> Pod-Wordlist-Author-TABULO | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 4 | ( my $inc = $dist ) =~ s!(-|::)!/!g; # e.g. Pod/Wordlist/Author/TABULO | |||||||||||||||||||
| 27 | 4 | $inc .= '.pm'; # e.g.: Pod/Wordlist/Author/TABULO.pm' | |||||||||||||||||||
| 28 | 4 | ▶ | my $pth = $INC{$inc} || ''; # e.g.: $BUILD(/blib)?/lib/Pod/Wordlist/Author/TABULO.pm' | ||||||||||||||||||
|
Condition50%1/2
$INC{$inc} || ''
MC/DC0%0/1
$INC{$inc} || ''
$INC{$inc}
Truth table50%1/2
A
A= $INC{$inc}
| |||||||||||||||||||||
| 29 | 4 | $pth =~ s/$inc$//; # e.g.: $BUILD(/blib)?/lib' | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # Handle the case where t looks like we are in a build directory or a in a development repo | ||||||||||||||||||||
| 32 | 4 | ▶ | for ( $pth || () ) { | ||||||||||||||||||
|
Condition33%1/3
$pth || ()
MC/DC0%0/2
$pth || ()
$pth
()
Truth table33%1/3
A || B
A= $pthB= ()
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 4 | my $path = path($pth); # convert to Path::Tiny object | |||||||||||||||||||
| 35 | 4 | $path = $path->parent->realpath; # strip trailing /lib | |||||||||||||||||||
| 36 | 4 | ▶ | $path = $path->parent if $path->basename eq "blib"; # In case the module might have been loaded from blib/lib. | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | # $path should now refer to $BUILD (or $REPO), hopefully. | ||||||||||||||||||||
| 38 | 4 | ▶ | next unless $path; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # Does it look like we are in a development repo (rather than in an installed location) ? | ||||||||||||||||||||
| 41 | 4 | my $in_repo; | |||||||||||||||||||
| 42 | 4 | foreach (qw/.gitignore Changes META.json Meta.yml README README.md dist.ini/) { | |||||||||||||||||||
| 43 | 8 | ▶ | $path->child($_)->exists and do { $in_repo=1; last }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | 4 | ▶ | next unless $in_repo // 0; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$in_repo // 0
MC/DC0%0/1
$in_repo // 0
$in_repo
Truth table50%1/2
A
A= $in_repo
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 4 | ▶ | next unless ($path = $path->child("share"))->is_dir; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 4 | return $path; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | 0 | require File::ShareDir; | |||||||||||||||||||
| 51 | 0 | return eval { path( File::ShareDir::dist_dir($dist) ) }; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | #endregion (UTILITY FUNCTIONS) | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | 1; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =pod | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =encoding UTF-8 | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =for :stopwords Tabulo[n] | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 NAME | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | Zest::Author::TABULO::Util::ShareDir - DZIL-related utility functions used by TABULO's authoring dist | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head1 VERSION | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | version 1.000014 | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =for Pod::Coverage dist_file dist_dir | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head1 AUTHORS | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | Tabulo[n] <dev@tabulo.net> | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head1 LEGAL | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | This software is copyright (c) 2023 by Tabulo[n]. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 85 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||