| 1 | package App::Grok::Resource::File; | ||||||||||
| 2 | 40 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 40 | $App::Grok::Resource::File::AUTHORITY = 'cpan:HINRIK'; | |||||||||
| 4 | } | ||||||||||
| 5 | { | ||||||||||
| 6 | 40 | $App::Grok::Resource::File::VERSION = '0.26'; | |||||||||
| 7 | } | ||||||||||
| 8 | |||||||||||
| 9 | 40 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 40 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 40 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 40 | our @EXPORT_OK = qw(file_index file_fetch file_locate); | |||||||||
| 14 | 40 | our %EXPORT_TAGS = ( ALL => [@EXPORT_OK] ); | |||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | sub file_fetch { | ||||||||
|
Subroutine
file_fetch: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 17 | 2 | my ($file) = @_; | |||||||||
| 18 | |||||||||||
| 19 | # TODO: at some point we'll search through $PERL6LIB, but for now | ||||||||||
| 20 | # we only accept a concrete path | ||||||||||
| 21 | |||||||||||
| 22 | 2 | ▶ | if (-f $file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | ▶ | open my $handle, '<', $file or die "Can't open $file: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 1 | my $pod = do { local $/ = undef; scalar <$handle> }; | |||||||||
| 25 | 1 | close $handle; | |||||||||
| 26 | 1 | return $pod; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | return; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub file_index { | ||||||||
|
Subroutine
file_index: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | # this might recurse through $PERL6LIB or something at some point | ||||||||||
| 34 | 0 | return; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub file_locate { | ||||||||
|
Subroutine
file_locate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 38 | 0 | my ($file) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | return $file if -f $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | return; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 40 | 1; | |||||||||
| 45 | |||||||||||
| 46 | =encoding utf8 | ||||||||||
| 47 | |||||||||||
| 48 | =head1 NAME | ||||||||||
| 49 | |||||||||||
| 50 | App::Grok::Resource::File - Standard file resource for grok | ||||||||||
| 51 | |||||||||||
| 52 | =head1 SYNOPSIS | ||||||||||
| 53 | |||||||||||
| 54 | use strict; | ||||||||||
| 55 | use warnings; | ||||||||||
| 56 | use App::Grok::Resource::File qw<:ALL>; | ||||||||||
| 57 | |||||||||||
| 58 | # this will return everything in $PERL6LIB sometime in the future | ||||||||||
| 59 | my @index = file_index(); | ||||||||||
| 60 | |||||||||||
| 61 | # get a filehandle to the thing we want | ||||||||||
| 62 | my $handle = file_fetch('perlintro'); | ||||||||||
| 63 | |||||||||||
| 64 | =head1 DESCRIPTION | ||||||||||
| 65 | |||||||||||
| 66 | This resource finds arbitrary documentation on the filesystem. | ||||||||||
| 67 | |||||||||||
| 68 | =head1 FUNCTIONS | ||||||||||
| 69 | |||||||||||
| 70 | =head2 C<file_index> | ||||||||||
| 71 | |||||||||||
| 72 | This method doesn't return anything useful yet. | ||||||||||
| 73 | |||||||||||
| 74 | =head2 C<file_fetch> | ||||||||||
| 75 | |||||||||||
| 76 | Takes a module name, program name, or Pod page name. Since the details of | ||||||||||
| 77 | C<$PERL6LIB> are still fuzzy, it currently just returns the contents of | ||||||||||
| 78 | the supplied file. | ||||||||||
| 79 | |||||||||||
| 80 | =head2 C<file_locate> | ||||||||||
| 81 | |||||||||||
| 82 | Returns the filename given if it is a real file. Not very useful. | ||||||||||
| 83 | |||||||||||
| 84 | =cut | ||||||||||