| 1 | package Email::MIME::Kit::KitReader::SWAK 1.093065; | ||||||||||||||||||||||||||||
| 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 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 46 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 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
Condition33%1/3
$old_kr and $old_kr->isa("Email::MIME::Kit::KitReader::Dir")
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")
| |||||||||||||||||||||||||||||
| 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 | 4 | ▶ | sub get_kit_entry { | ||||||||||||||||||||||||||
|
Subroutine
get_kit_entry: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 4 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | my $content = $self->resolver->entity_at($path)->content_ref; | |||||||||||||||||||||||||||
| 78 | 4 | ▶ | return $content if $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | confess "no content for $path"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||