| 1 | package MooseX::Templated::Util; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | MooseX::Templated::Util - helper methods | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use MooseX::Templated::Util qw/ where_pm /; | ||||||||||
| 10 | |||||||||||
| 11 | =head1 METHODS | ||||||||||
| 12 | |||||||||||
| 13 | =head2 where_pm( 'ClassName' ) | ||||||||||
| 14 | |||||||||||
| 15 | Returns the file path information for a given class path | ||||||||||
| 16 | |||||||||||
| 17 | $abs_file = where_pm( 'Some::Module' ); | ||||||||||
| 18 | # /path/to/Some/Module.pm | ||||||||||
| 19 | |||||||||||
| 20 | ($abs_file, $inc_path, $require) = where_pm( 'Some::Module' ); | ||||||||||
| 21 | |||||||||||
| 22 | # /path/to/Some/Module.pm | ||||||||||
| 23 | # /path/to | ||||||||||
| 24 | # Some/Module.pm | ||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 5 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 5 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 5 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 5 | our (@ISA, @EXPORT_OK); | |||||||||
| 36 | 5 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 5 | require Exporter; | |||||||||
| 38 | 5 | @ISA = qw/ Exporter /; | |||||||||
| 39 | 5 | @EXPORT_OK = qw/ where_pm /; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # This is a drop-in rewrite of a similar function in Find::Where | ||||||||||
| 43 | # (which no longer installs on perl > 5.22 and doesn't look | ||||||||||
| 44 | # like it's going to be fixed anytime soon) | ||||||||||
| 45 | 15 | ▶ | sub where_pm { | ||||||||
|
Subroutine
where_pm: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 46 | 15 | my $class = shift; | |||||||||
| 47 | 15 | my $inc_path = \@INC; | |||||||||
| 48 | 15 | my $abs_file; | |||||||||
| 49 | my $require; | ||||||||||
| 50 | |||||||||||
| 51 | 15 | my @module_parts = split( '::', $class ); | |||||||||
| 52 | 15 | $module_parts[-1] .= '.pm'; | |||||||||
| 53 | |||||||||||
| 54 | # go through each PATH and return the first file we find | ||||||||||
| 55 | 15 | PATH: foreach my $path ( @$inc_path ) { | |||||||||
| 56 | 47 | my $module_file_abs = file( $path, @module_parts ); | |||||||||
| 57 | 47 | ▶ | if ( -f $module_file_abs ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 11 | $abs_file = "" . $module_file_abs->absolute; | |||||||||
| 59 | 11 | $inc_path = "" . dir( $path ); | |||||||||
| 60 | 11 | $require = "" . file( @module_parts ); | |||||||||
| 61 | 11 | last PATH; | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | 15 | ▶ | return wantarray ? ($abs_file, $inc_path, $require) : $abs_file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 5 | 1; | |||||||||