| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Module::Filename; | 
| 2 | 3 |  |  | 3 |  | 76878 | use strict; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 145 |  | 
| 3 | 3 |  |  | 3 |  | 18 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 120 |  | 
| 4 | 3 |  |  | 3 |  | 18 | use base qw{Exporter}; | 
|  | 3 |  |  |  |  | 10 |  | 
|  | 3 |  |  |  |  | 387 |  | 
| 5 | 3 |  |  | 3 |  | 21212 | use Path::Class qw{file}; | 
|  | 3 |  |  |  |  | 224344 |  | 
|  | 3 |  |  |  |  | 1144 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.02'; | 
| 8 |  |  |  |  |  |  | our @EXPORT_OK = qw(module_filename); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 NAME | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | Module::Filename - Provides an object oriented, cross platform interface for getting a module's filename | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | use Module::Filename; | 
| 17 |  |  |  |  |  |  | my $filename=Module::Filename->new->filename("Test::More"); #isa Path::Class::File | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | use Module::Filename qw{module_filename}; | 
| 20 |  |  |  |  |  |  | my $filename=module_filename("Test::More");                 #isa Path::Class::File | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | This module returns the filename as a L object.  It does not load any packages as it scans.  It simply scans @INC looking for a module of the same name as the package passed. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head1 USAGE | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | use Module::Filename; | 
| 29 |  |  |  |  |  |  | my $filename=Module::Filename->new->filename("Test::More"); #isa Path::Class::File | 
| 30 |  |  |  |  |  |  | print "Test::More can be found at $filename\n"; | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 CONSTRUCTOR | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head2 new | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | my $mf=Module::Filename->new(); | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =cut | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub new { | 
| 41 | 2 |  |  | 2 | 1 | 24 | my $this = shift(); | 
| 42 | 2 |  | 33 |  |  | 21 | my $class = ref($this) || $this; | 
| 43 | 2 |  |  |  |  | 5 | my $self = {}; | 
| 44 | 2 |  |  |  |  | 6 | bless $self, $class; | 
| 45 | 2 |  |  |  |  | 14 | $self->initialize(@_); | 
| 46 | 2 |  |  |  |  | 7 | return $self; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head1 METHODS | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head2 initialize | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | You can inherit the filename method in your package. | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | use base qw{Module::Filename}; | 
| 56 |  |  |  |  |  |  | sub initialize{do_something_else()}; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =cut | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub initialize { | 
| 61 | 2 |  |  | 2 | 1 | 5 | my $self = shift(); | 
| 62 | 2 |  |  |  |  | 24 | %$self=@_; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head2 filename | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | Returns a L object for the first filename that matches the module in the @INC path array. | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | my $filename=Module::Filename->new->filename("Test::More"); #isa Path::Class::File | 
| 70 |  |  |  |  |  |  | print "Filename: $filename\n"; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =cut | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub filename { | 
| 75 | 5 |  |  | 5 | 1 | 922 | my $self=shift; | 
| 76 | 5 |  |  |  |  | 15 | return module_filename(@_); | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head2 module_filename | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | Returns a L object for the first filename that matches the module in the @INC path array. | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | my $filname=module_filename("Test::More"); #isa Path::Class::File | 
| 86 |  |  |  |  |  |  | print "Filename: $filename\n"; | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =cut | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | sub module_filename { | 
| 92 | 10 | 50 |  | 10 | 1 | 47 | die("Error: Module name required.") unless @_; | 
| 93 | 10 |  |  |  |  | 19 | my $module=shift; | 
| 94 | 10 |  |  |  |  | 70 | my $file=file(split("::", $module.".pm")); | 
| 95 | 10 |  |  |  |  | 1097 | my $return=undef; | 
| 96 | 10 |  |  |  |  | 24 | foreach my $path (@INC) { | 
| 97 | 98 | 50 |  |  |  | 3953 | next unless defined $path; | 
| 98 | 98 | 50 |  |  |  | 175 | next if ref($path); | 
| 99 | 98 |  |  |  |  | 213 | my $filename=file($path,  $file); | 
| 100 | 98 | 100 |  |  |  | 7788 | if (-f $filename) { | 
| 101 | 8 |  |  |  |  | 385 | $return=$filename; | 
| 102 | 8 |  |  |  |  | 232 | last; #return the first match in @INC | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  | } | 
| 105 | 10 |  |  |  |  | 167 | return $return; | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =head1 LIMITATIONS | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | The algorithm does not scan inside module files for provided packages. | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =head1 BUGS | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | Submit to RT and email author. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 SUPPORT | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | DavisNetworks.com supports all Perl applications including this package. | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 AUTHOR | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | Michael R. Davis | 
| 124 |  |  |  |  |  |  | CPAN ID: MRDVT | 
| 125 |  |  |  |  |  |  | STOP, LLC | 
| 126 |  |  |  |  |  |  | domain=>michaelrdavis,tld=>com,account=>perl | 
| 127 |  |  |  |  |  |  | http://www.stopllc.com/ | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | This program is free software licensed under the... | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | The BSD License | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | The full text of the license can be found in the LICENSE file included with this module. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | Module::Filename predates L by almost 4 years but it appears more people prefer L over Module::Filename as it does not have the dependency on L.  After the reviews on L. I added the functional API to Module::Filename.  So, your decision is simply an object/non-object decision.   The operations with the file system that both packages perform outweigh the performance of the object creation in Module::Filename.  So, any performance penalty should not be measurable.  Since Module::Filename does not need three extra file test operations that Module::Path 0.18 performs on each @INC directory, Module::Filename may actually be faster than L for most applications. | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head2 Similar Capabilities | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | L, L %INC, L, L constructor=>new_from_module, method=>file, L property=>"dir", L method=>locate, L method=>find_installed | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head2 Comparison | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | CPAN modules for getting a module's path L | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =cut | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | 1; |