File Coverage

blib/lib/App/Grok/Resource/File.pm
Criterion Covered Total %
statement 10 23 43.4
branch 0 6 0.0
condition n/a
subroutine 4 7 57.1
pod 3 3 100.0
total 17 39 43.5


line stmt bran cond sub pod time code
1             package App::Grok::Resource::File;
2             BEGIN {
3 1     1   37 $App::Grok::Resource::File::AUTHORITY = 'cpan:HINRIK';
4             }
5             {
6             $App::Grok::Resource::File::VERSION = '0.26';
7             }
8              
9 1     1   7 use strict;
  1         3  
  1         47  
10 1     1   9 use warnings FATAL => 'all';
  1         2  
  1         51  
11              
12 1     1   6 use base qw(Exporter);
  1         2  
  1         323  
13             our @EXPORT_OK = qw(file_index file_fetch file_locate);
14             our %EXPORT_TAGS = ( ALL => [@EXPORT_OK] );
15              
16             sub file_fetch {
17 0     0 1   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 0 0         if (-f $file) {
23 0 0         open my $handle, '<', $file or die "Can't open $file: $!";
24 0           my $pod = do { local $/ = undef; scalar <$handle> };
  0            
  0            
25 0           close $handle;
26 0           return $pod;
27             }
28              
29 0           return;
30             }
31              
32             sub file_index {
33             # this might recurse through $PERL6LIB or something at some point
34 0     0 1   return;
35             }
36              
37             sub file_locate {
38 0     0 1   my ($file) = @_;
39            
40 0 0         return $file if -f $file;
41 0           return;
42             }
43              
44             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