| 1 | package Langertha::Raider::Instructions; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Internal resolver of the project instructions file | ||||||||||||||||||||||||||||
| 3 | 75 | our $VERSION = '0.503'; | |||||||||||||||||||||||||||
| 4 | 75 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 75 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 75 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 75 | ▶ | use Langertha::Raider::Home; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 75 | has root => ( | |||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||
| 12 | isa => 'Str', | ||||||||||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 903 | ▶ | sub home_class { 'Langertha::Raider::Home' } | ||||||||||||||||||||||||||
|
Subroutine
home_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 868 | ▶ | sub native_file { $_[0]->home_class->project_base($_[0]->root)->child('instructions.md') } | ||||||||||||||||||||||||||
|
Subroutine
native_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 351 | ▶ | sub legacy_file { path($_[0]->root)->child('.raider.md') } | ||||||||||||||||||||||||||
|
Subroutine
legacy_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 325 | ▶ | sub file { | ||||||||||||||||||||||||||
|
Subroutine
file: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 325 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 25 | 325 | my $native = $self->native_file; | |||||||||||||||||||||||||||
| 26 | 325 | ▶ | return -f $native ? $native : $self->legacy_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 534 | ▶ | sub is_native { -f $_[0]->native_file ? 1 : 0 } | ||||||||||||||||||||||||||
|
Subroutine
is_native: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 315 | ▶ | sub label { $_[0]->is_native ? $_[0]->home_class->dir_name.'/instructions.md' : '.raider.md' } | ||||||||||||||||||||||||||
|
Subroutine
label: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 149 | ▶ | sub file_exists { -f $_[0]->file ? 1 : 0 } | ||||||||||||||||||||||||||
|
Subroutine
file_exists: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 149 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 149 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 38 | 149 | my $file = $self->file; | |||||||||||||||||||||||||||
| 39 | 149 | ▶ | return unless -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 18 | my $text = eval { $file->slurp_utf8 }; | |||||||||||||||||||||||||||
| 41 | 18 | ▶ | return defined $text && length $text ? $text : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $text and length $text
MC/DC0%0/2
defined $text and length $text
defined $text
length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 217 | ▶ | sub ignored_files { | ||||||||||||||||||||||||||
|
Subroutine
ignored_files: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 217 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 47 | 217 | ▶ | return unless $self->is_native && -f $self->legacy_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->is_native and -f $self->legacy_file
MC/DC100%2/2
$self->is_native and -f $self->legacy_file
$self->is_native
-f $self->legacy_file
Truth table100%3/3
A and B
A= $self->is_nativeB= -f $self->legacy_file
| |||||||||||||||||||||||||||||
| 48 | 6 | my $label = $self->label; | |||||||||||||||||||||||||||
| 49 | return { | ||||||||||||||||||||||||||||
| 50 | 6 | file => $self->legacy_file->absolute->stringify, | |||||||||||||||||||||||||||
| 51 | reason => 'both .raider.md and '.$label.' exist; only '.$label.' is used', | ||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 75 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 75 | 1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =pod | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 NAME | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Langertha::Raider::Instructions - Internal resolver of the project instructions file | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 VERSION | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | version 0.503 | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Internal to Langertha-Raider -- no API promise. | ||||||||||||||||||||||||||||
| 76 | my $instructions = Langertha::Raider::Instructions->new(root => $root); | ||||||||||||||||||||||||||||
| 77 | my $text = $instructions->text; # undef when absent or empty | ||||||||||||||||||||||||||||
| 78 | my $label = $instructions->label; # '.raider/instructions.md' or '.raider.md' | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | B<Internal module.> Its interface may change without notice. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Knows which file holds the project instructions of L</root> (ADR 0011): | ||||||||||||||||||||||||||||
| 85 | F<.raider/instructions.md> when it exists, else the legacy F<.raider.md>. | ||||||||||||||||||||||||||||
| 86 | When both exist, only F<.raider/instructions.md> is used and the legacy | ||||||||||||||||||||||||||||
| 87 | file is reported by L</ignored_files>. The same rule as | ||||||||||||||||||||||||||||
| 88 | L<Langertha::Raider::Config> for F<.raider/config.yml>. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Unlike L<Langertha::Raider::Config/file>, L</file> is decided on every | ||||||||||||||||||||||||||||
| 91 | call, so a file created during a session (C</prompt>, by hand before | ||||||||||||||||||||||||||||
| 92 | C</reload>) is seen on the next reload. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head2 root | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | The project directory. Required. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 native_file | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | L<Path::Tiny> of F<.raider/instructions.md> in L</root>, present or not. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 legacy_file | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | L<Path::Tiny> of F<.raider.md> in L</root>, present or not. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head2 file | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | L<Path::Tiny> of the file in use: L</native_file> when it exists, else | ||||||||||||||||||||||||||||
| 109 | L</legacy_file>. Writers (the prompt-builder) write here, so without any | ||||||||||||||||||||||||||||
| 110 | file they create the legacy F<.raider.md>, never F<.raider/instructions.md>. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head2 is_native | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | True when L</file> is F<.raider/instructions.md>. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head2 label | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | The file in use relative to L</root>, C<.raider/instructions.md> or | ||||||||||||||||||||||||||||
| 119 | C<.raider.md>: how reports name it as a source. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head2 file_exists | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | True when L</file> exists. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head2 text | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | The content of L</file>, or C<undef> when it is absent, unreadable or | ||||||||||||||||||||||||||||
| 128 | empty. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head2 ignored_files | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | for my $ign ($instructions->ignored_files) { | ||||||||||||||||||||||||||||
| 133 | warn 'ignoring '.$ign->{file}.': '.$ign->{reason}."\n"; | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | The instructions files that are present but not used, each as C<file> | ||||||||||||||||||||||||||||
| 137 | (absolute path) and C<reason>: the legacy F<.raider.md> while | ||||||||||||||||||||||||||||
| 138 | F<.raider/instructions.md> is in use. Empty otherwise. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =over | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =item * L<Langertha::Raider::Application/mission> | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =item * L<Langertha::Raider::Config> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =back | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head2 Issues | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||
| 155 | L<https://github.com/Getty/langertha-raider/issues>. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head2 IRC | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | This software is copyright (c) 2026 by Torsten Raudssus. | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 174 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||||||||||