« blib/lib/Dist/Zilla/Plugin/DBIO/CoverageGate.pm
↑ Summary
blib/lib/Dist/Zilla/PluginBundle/DBIO.pm »
| 1 | package Dist::Zilla::Plugin::DBIO::GatherSkills; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Ship a distribution's own agent skills as a sharedir (share/skills/) | ||||||||||||||||||||||||||||
| 3 | 8 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Dist::Zilla::File::InMemory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | has skill => ( | ||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||
| 12 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||
| 13 | lazy => 1, | ||||||||||||||||||||||||||||
| 14 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 8 | ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 28 | ▶ | sub mvp_multivalue_args { qw(skill) } | ||||||||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 8 | has from => ( | |||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => 'Str', | ||||||||||||||||||||||||||||
| 23 | default => '.claude/skills', | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | ▶ | sub _owned { | ||||||||||||||||||||||||||
|
Subroutine
_owned: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||
| 27 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 28 | 7 | ▶ | return @{ $self->skill } if @{ $self->skill }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Fallback: skills named after the distribution (e.g. DBIO-DB2 -> dbio-db2*). | ||||||||||||||||||||||||||||
| 31 | 3 | my $slug = lc $self->zilla->name; | |||||||||||||||||||||||||||
| 32 | 3 | my $base = path($self->from); | |||||||||||||||||||||||||||
| 33 | 3 | ▶ | return unless $base->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | my @owned; | |||||||||||||||||||||||||||
| 36 | 1 | for my $child (grep { $_->is_dir } $base->children) { | |||||||||||||||||||||||||||
| 37 | 1 | my $name = $child->basename; | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | push @owned, $name if $name eq $slug or index($name, "$slug-") == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name eq $slug or index($name, "$slug-") == 0
MC/DC0%0/2
$name eq $slug or index($name, "$slug-") == 0
$name eq $slug
index($name, "$slug-") == 0
Truth table33%1/3
A or B
A= $name eq $slugB= index($name, "$slug-") == 0
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 1 | return sort @owned; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 7 | ▶ | sub gather_files { | ||||||||||||||||||||||||||
|
Subroutine
gather_files: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 45 | 7 | my $base = path($self->from); | |||||||||||||||||||||||||||
| 46 | 7 | ▶ | my $explicit = @{ $self->skill } ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 7 | for my $name ($self->_owned) { | |||||||||||||||||||||||||||
| 49 | 5 | my $dir = $base->child($name); | |||||||||||||||||||||||||||
| 50 | 5 | ▶ | unless ($dir->is_dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 1 | my $missing = "owned skill '$name' not found under @{[$self->from]}"; | |||||||||||||||||||||||||||
| 52 | # An explicitly declared skill (share_skill=/skill=) that is not on disk | ||||||||||||||||||||||||||||
| 53 | # is fatal: a build without a prior skilletor sync must fail loud, not | ||||||||||||||||||||||||||||
| 54 | # silently ship a dist missing a declared skill. The name-derived fallback | ||||||||||||||||||||||||||||
| 55 | # (empty skill list) stays a silent skip -- there "nothing matches" is a | ||||||||||||||||||||||||||||
| 56 | # valid answer, not an error. | ||||||||||||||||||||||||||||
| 57 | 1 | ▶ | $self->log_fatal($missing) if $explicit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $self->log("$missing -- skipping"); | |||||||||||||||||||||||||||
| 59 | 0 | next; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | my $iter = $dir->iterator({ recurse => 1 }); | |||||||||||||||||||||||||||
| 63 | 4 | ▶ | while (my $file = $iter->()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 10 | ▶ | next unless $file->is_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | # skilletor writes a per-skill .gitignore (content "*") into every | ||||||||||||||||||||||||||||
| 66 | # installed skill dir; it is management state, not skill content, and must | ||||||||||||||||||||||||||||
| 67 | # never be shipped into the tarball. Everything else ships byte for byte. | ||||||||||||||||||||||||||||
| 68 | 8 | ▶ | next if $file->basename eq '.gitignore'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 6 | my $rel = $file->relative($base); # e.g. dbio-db2/SKILL.md | |||||||||||||||||||||||||||
| 70 | 6 | $self->add_file(Dist::Zilla::File::InMemory->new( | |||||||||||||||||||||||||||
| 71 | name => "share/skills/$rel", | ||||||||||||||||||||||||||||
| 72 | encoded_content => $file->slurp_raw, # bytes as they are: binary files survive | ||||||||||||||||||||||||||||
| 73 | )); | ||||||||||||||||||||||||||||
| 74 | 6 | $self->log_debug("gathered share/skills/$rel"); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 80 | 8 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | 8 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||