| 1 | package Dist::Build::Util; | ||
| 2 | $Dist::Build::Util::VERSION = '0.028'; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Exporter 5.57 'import'; | ||
| 7 | our @EXPORT_OK = qw/dist_dir module_dir/; | ||
| 8 | our %EXPORT_TAGS = (sharedir => \@EXPORT_OK); | ||
| 9 | |||
| 10 | use Carp 'croak'; | ||
| 11 | use File::Spec::Functions 'catdir'; | ||
| 12 | |||
| 13 | sub _search_inc_path { | ||
| 14 | my $path = catdir(@_); | ||
| 15 | |||
| 16 | for my $candidate (@INC) { | ||
| 17 | next if ref $candidate; | ||
| 18 | my $dir = catdir($candidate, $path); | ||
| 19 | return $dir if -d $dir; | ||
| 20 | } | ||
| 21 | |||
| 22 | return undef; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub dist_dir { | ||
| 26 | my $dist = shift; | ||
| 27 | |||
| 28 | croak 'No dist given' if not length $dist; | ||
| 29 | my $dir = _search_inc_path('auto', 'share', 'dist', $dist); | ||
| 30 | |||
| 31 | croak("Failed to find share dir for dist '$dist'") if not defined $dir; | ||
| 32 | return $dir; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub module_dir { | ||
| 36 | my $module = shift; | ||
| 37 | |||
| 38 | croak 'No module given' if not length $module; | ||
| 39 | (my $module_dir = $module) =~ s/::/-/g; | ||
| 40 | my $dir = _search_inc_path('auto', 'share', 'module', $module_dir); | ||
| 41 | |||
| 42 | croak("Failed to find share dir for module '$module'") if not defined $dir; | ||
| 43 | return $dir; | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; | ||
| 47 | |||
| 48 | # ABSTRACT: Utility functions for Dist::Build | ||
| 49 | |||
| 50 | __END__ |