File Coverage

blib/lib/Path/Resolver/Role/FileResolver.pm
Criterion Covered Total %
statement 22 23 95.6
branch n/a
condition n/a
subroutine 8 9 88.8
pod 0 2 0.0
total 30 34 88.2


line stmt bran cond sub pod time code
1             package Path::Resolver::Role::FileResolver 3.100455;
2             # ABSTRACT: a resolver that natively finds absolute file paths
3 1     1   913 use Moose::Role;
  1         4218  
  1         3  
4             with 'Path::Resolver::Role::Resolver' => { -excludes => 'default_converter' };
5              
6 1     1   5170 use autodie;
  1         11861  
  1         4  
7 1     1   5804 use namespace::autoclean;
  1         3  
  1         8  
8              
9 1     1   601 use Path::Resolver::SimpleEntity;
  1         3  
  1         37  
10 1     1   460 use Path::Resolver::Types qw(AbsFilePath);
  1         3  
  1         19  
11 1     1   1333 use Path::Resolver::CustomConverter;
  1         4  
  1         8  
12              
13 1     1   386 use MooseX::Types;
  1         2  
  1         8  
14              
15             #pod =head1 SYNOPSIS
16             #pod
17             #pod The FileResolver role is a specialized form of the Resolver role, and can be
18             #pod used in its place. (Anything that does the FileResolver role automatically
19             #pod does the Resolver role, too.)
20             #pod
21             #pod FileResolver classes have a native type of Path::Resolver::Types::AbsFilePath
22             #pod (from L<Path::Resolver::Types>). Basically, they will natively return a
23             #pod Path::Class::File pointing to an absolute file path.
24             #pod
25             #pod FileResolver classes also have a default converter that will convert the
26             #pod AbsFilePath to a L<Path::Resolver::SimpleEntity>, meaning that by default a
27             #pod FileResolver's C<entity_at> will return a SimpleEntity. This entity will be
28             #pod constructed by reading the file B<in raw mode>. In other words, it is the
29             #pod byte string contents of the file, not any decoded character string. If you
30             #pod want to a Unicode string of a file's contents, you must decode it yourself.
31             #pod
32             #pod =cut
33              
34 0     0 0 0 sub native_type { AbsFilePath }
35              
36             my $converter = Path::Resolver::CustomConverter->new({
37             input_type => AbsFilePath,
38             output_type => class_type('Path::Resolver::SimpleEntity'),
39             converter => sub {
40             my ($converter, $abs_path) = @_;
41              
42             open my $fh, '<:raw', "$abs_path";
43             my $content = do { local $/; <$fh> };
44             Path::Resolver::SimpleEntity->new({ content_ref => \$content });
45             },
46             });
47              
48 3     3 0 2440 sub default_converter { $converter }
49              
50             1;
51              
52             __END__
53              
54             =pod
55              
56             =encoding UTF-8
57              
58             =head1 NAME
59              
60             Path::Resolver::Role::FileResolver - a resolver that natively finds absolute file paths
61              
62             =head1 VERSION
63              
64             version 3.100455
65              
66             =head1 SYNOPSIS
67              
68             The FileResolver role is a specialized form of the Resolver role, and can be
69             used in its place. (Anything that does the FileResolver role automatically
70             does the Resolver role, too.)
71              
72             FileResolver classes have a native type of Path::Resolver::Types::AbsFilePath
73             (from L<Path::Resolver::Types>). Basically, they will natively return a
74             Path::Class::File pointing to an absolute file path.
75              
76             FileResolver classes also have a default converter that will convert the
77             AbsFilePath to a L<Path::Resolver::SimpleEntity>, meaning that by default a
78             FileResolver's C<entity_at> will return a SimpleEntity. This entity will be
79             constructed by reading the file B<in raw mode>. In other words, it is the
80             byte string contents of the file, not any decoded character string. If you
81             want to a Unicode string of a file's contents, you must decode it yourself.
82              
83             =head1 PERL VERSION
84              
85             This library should run on perls released even a long time ago. It should work
86             on any version of perl released in the last five years.
87              
88             Although it may work on older versions of perl, no guarantee is made that the
89             minimum required version will not be increased. The version may be increased
90             for any reason, and there is no promise that patches will be accepted to lower
91             the minimum required perl.
92              
93             =head1 AUTHOR
94              
95             Ricardo Signes <cpan@semiotic.systems>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is copyright (c) 2022 by Ricardo Signes.
100              
101             This is free software; you can redistribute it and/or modify it under
102             the same terms as the Perl 5 programming language system itself.
103              
104             =cut