1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
package Dist::Build::Util;
$Dist::Build::Util::VERSION = '0.025';
use strict;
use warnings;
use Exporter 5.57 'import';
our @EXPORT_OK = qw/dist_dir module_dir/;
our %EXPORT_TAGS = (sharedir => \@EXPORT_OK);
use Carp 'croak';
use File::Spec::Functions 'catdir';
sub _search_inc_path {
my $path = catdir(@_);
for my $candidate (@INC) {
next if ref $candidate;
my $dir = catdir($candidate, $path);
return $dir if -d $dir;
}
return undef;
}
sub dist_dir {
my $dist = shift;
croak 'No dist given' if not length $dist;
my $dir = _search_inc_path('auto', 'share', 'dist', $dist);
croak("Failed to find share dir for dist '$dist'") if not defined $dir;
return $dir;
}
sub module_dir {
my $module = shift;
croak 'No module given' if not length $module;
(my $module_dir = $module) =~ s/::/-/g;
my $dir = _search_inc_path('auto', 'share', 'module', $module_dir);
croak("Failed to find share dir for module '$module'") if not defined $dir;
return $dir;
}
1;
# ABSTRACT: Utility functions for Dist::Build
__END__
=pod
=encoding UTF-8
=head1 NAME
Dist::Build::Util - Utility functions for Dist::Build
=head1 VERSION
version 0.025
=head1 SYNOPSIS
use Dist::Build::Util 'module_dir';
say module_dir('Dist::Build');
=head1 DESCRIPTION
This module contains a collection of utility functions for L<Dist::Build>. Currently it contains only sharedir functions, but in the future more functions may be added.
=head1 FUNCTIONS
=head2 dist_dir
# Get a distribution's shared files directory
my $dir = dist_dir('My-Distribution');
The C<dist_dir> function takes a single parameter of the name of an
installed (CPAN or otherwise) distribution, and locates the shared
data directory created at install time for it.
Returns the directory path as a string, or dies if it cannot be
located or is not readable.
This is part of the C<:sharedir> export group.
=head2 module_dir
# Get a module's shared files directory
my $dir = module_dir('My::Module');
The C<module_dir> function takes a single parameter of the name of an
installed (CPAN or otherwise) module, and locates the shared data
directory created at install time for it.
Returns the directory path as a string, or dies if it cannot be
located or is not readable.
This is part of the C<:sharedir> export group.
=head1 AUTHOR
Leon Timmermans <fawaka@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|