blib/lib/Email/MIME/Kit/KitReader/SWAK.pm

filter: Statementstmt 96.8% 31 / 32 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 82.6% 43 / 52 SCAR 13.9
CC
4
Cov
87%
__ANON__
3.1
get_kit_entry
2.1
BEGIN
1.0
CRAP 4.0
↑ Summary
1 package Email::MIME::Kit::KitReader::SWAK 1.093064;
2 # ABSTRACT: the swiss army knife of EMK kit readers
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 with 'Email::MIME::Kit::Role::KitReader';
6  
7 #pod =head1 DESCRIPTION
8 #pod
9 #pod This replaces and extends the standard (Dir) kit reader for Email::MIME::Kit,
10 #pod letting your kit refer to resources in locations other than the kit itself.
11 #pod
12 #pod In your manifest (assuming it's YAML, for readability):
13 #pod
14 #pod ---
15 #pod kit_reader: SWAK
16 #pod attachments:
17 #pod - type: text/html
18 #pod path: template.html
19 #pod
20 #pod - type: text/plain
21 #pod path: /dist/Your-App/config.conf
22 #pod
23 #pod - type: text/plain
24 #pod path: /fs/etc/motd
25 #pod
26 #pod This will find the first file in the kit (the absolute path prefix F</kit>
27 #pod could also be used), the second file in the L<File::ShareDir|File::ShareDir>
28 #pod shared dist space for the Your-App, and the third file on the root filesystem.
29 #pod
30 #pod SWAK may be given a C<fs_root> option to start the contents of F</fs> somewhere
31 #pod other than root.
32 #pod
33 #pod =cut
34  
35 1 ▶use Path::Resolver::Resolver::Mux::Prefix;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use Path::Resolver::Resolver::FileSystem;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use Path::Resolver::Resolver::AnyDist;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 has resolver => (
40 reader => 'resolver',
41 writer => '_set_resolver',
42 does => 'Path::Resolver::Role::Resolver',
43 init_arg => undef,
44 lazy => 1,
45 default => sub {
46 1 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.4
47 1 ▶ my $prs = sub { 'Path::Resolver::Resolver::' . $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
48  
49 1 my $old_kr = $self->kit->kit_reader;
50 1 ▶ confess(__PACKAGE__ . ' must (for now) replace an existing KitReader::Dir')
Branch: 1 branch
BranchTrueFalseTotal
unless $old_kr and $old_kr->isa("Email::MIME::Kit::KitReader::Dir") 0 1 1
Condition33%1/3
$old_kr and $old_kr->isa("Email::MIME::Kit::KitReader::Dir")
!ll&&!rl&&r
001
MC/DC0%0/2
$old_kr and $old_kr->isa("Email::MIME::Kit::KitReader::Dir")
$old_kr $old_kr->isa("Email::MIME::Kit::KitReader::Dir")
Truth table33%1/3
A and B
A= $old_krB= $old_kr->isa("Email::MIME::Kit::KitReader::Dir")
ABresult
0X0
100
111
51 unless $old_kr and $old_kr->isa('Email::MIME::Kit::KitReader::Dir');
52
53 1 my $kit_resolver = $prs->('FileSystem')->new({
54 root => $self->kit->source,
55 });
56  
57 1 Path::Resolver::Resolver::Mux::Prefix->new({
58 prefixes => {
59 fs => $prs->('FileSystem')->new({ root => $self->fs_root }),
60 dist => $prs->('AnyDist')->new,
61 kit => $kit_resolver,
62 q{} => $kit_resolver,
63 },
64 });
65 },
66 1 );
67  
68 1 has fs_root => (
69 is => 'ro',
70 isa => 'Str',
71 default => '/',
72 );
73  
74 sub get_kit_entry {
75 4 ▶ my ($self, $path) = @_;
Subroutine get_kit_entry: called CC=2 SCAR=7.6
Pod undocumented
76  
77 4 my $content = $self->resolver->entity_at($path)->content_ref;
78 4 ▶ return $content if $content;
Branch: 1 branch
BranchTrueFalseTotal
if $content 4 0 4
79  
80 0 confess "no content for $path";
81 }
82  
83 sub BUILD {
84 1 ▶ my ($self) = @_;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
85 1 $self->resolver;
86 }
87  
88 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 1 __PACKAGE__->meta->make_immutable;
90  
91 __END__
92  
93 =pod
94  
95 =encoding UTF-8
96  
97 =head1 NAME
98  
99 Email::MIME::Kit::KitReader::SWAK - the swiss army knife of EMK kit readers
100  
101 =head1 VERSION
102  
103 version 1.093064
104  
105 =head1 DESCRIPTION
106  
107 This replaces and extends the standard (Dir) kit reader for Email::MIME::Kit,
108 letting your kit refer to resources in locations other than the kit itself.
109  
110 In your manifest (assuming it's YAML, for readability):
111  
112 ---
113 kit_reader: SWAK
114 attachments:
115 - type: text/html
116 path: template.html
117  
118 - type: text/plain
119 path: /dist/Your-App/config.conf
120  
121 - type: text/plain
122 path: /fs/etc/motd
123  
124 This will find the first file in the kit (the absolute path prefix F</kit>
125 could also be used), the second file in the L<File::ShareDir|File::ShareDir>
126 shared dist space for the Your-App, and the third file on the root filesystem.
127  
128 SWAK may be given a C<fs_root> option to start the contents of F</fs> somewhere
129 other than root.
130  
131 =head1 PERL VERSION
132  
133 This module should work on any version of perl still receiving updates from
134 the Perl 5 Porters. This means it should work on any version of perl released
135 in the last two to three years. (That is, if the most recently released
136 version is v5.40, then this module should work on both v5.40 and v5.38.)
137  
138 Although it may work on older versions of perl, no guarantee is made that the
139 minimum required version will not be increased. The version may be increased
140 for any reason, and there is no promise that patches will be accepted to lower
141 the minimum required perl.
142  
143 =head1 AUTHOR
144  
145 Ricardo SIGNES <rjbs@semiotic.systems>
146  
147 =head1 COPYRIGHT AND LICENSE
148  
149 This software is copyright (c) 2022 by Ricardo SIGNES.
150  
151 This is free software; you can redistribute it and/or modify it under
152 the same terms as the Perl 5 programming language system itself.
153  
154 =cut
↑ Summary