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