| 1 | # | ||||||||||||||||||||
| 2 | # This file is part of Dist-Zilla-Role-RegisterStash | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | # This software is Copyright (c) 2012 by Chris Weyl. | ||||||||||||||||||||
| 5 | # | ||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||
| 9 | # | ||||||||||||||||||||
| 10 | package Dist::Zilla::Role::RegisterStash; | ||||||||||||||||||||
| 11 | 3 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | $Dist::Zilla::Role::RegisterStash::AUTHORITY = 'cpan:RSRCHBOY'; | |||||||||||||||||||
| 13 | } | ||||||||||||||||||||
| 14 | # git description: 0.002-6-g7034f16 | ||||||||||||||||||||
| 15 | 3 | $Dist::Zilla::Role::RegisterStash::VERSION = '0.003'; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | # ABSTRACT: A plugin that can register stashes | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 3 | ▶ | use Class::Load; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 3 | ▶ | use Dist::Zilla 4.3 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # so, we're a little sneaky here. It's possible to register stashes w/o | ||||||||||||||||||||
| 27 | # touching any "private" attributes or methods in the zilla object while it is | ||||||||||||||||||||
| 28 | # being built from the configuration, but we don't always want to create them | ||||||||||||||||||||
| 29 | # then. (Think of it like a lazy attribute -- we don't want to build it until | ||||||||||||||||||||
| 30 | # we need it, and it may be created further down in the configuration | ||||||||||||||||||||
| 31 | # anyways.) | ||||||||||||||||||||
| 32 | # | ||||||||||||||||||||
| 33 | # instead we generate a coderef capturing our assembler, and stash that away. | ||||||||||||||||||||
| 34 | # If we need to register a stash later, we'll be able to access the | ||||||||||||||||||||
| 35 | # registration method as if we were during the build stage. | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 3 | has _register_stash_method => ( | |||||||||||||||||||
| 38 | traits => ['Code'], | ||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||
| 40 | isa => 'CodeRef', | ||||||||||||||||||||
| 41 | handles => { | ||||||||||||||||||||
| 42 | _register_stash => 'execute', | ||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 2 | ▶ | before register_component => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 47 | 2 | my ($class, $name, $arg, $section) = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | my $assembler = $section->sequence->assembler; | |||||||||||||||||||
| 50 | 2 | ▶ | $arg->{_register_stash_method} ||= sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 2 | $assembler->register_stash(@_); | |||||||||||||||||||
| 52 | 2 | ▶ | }; | ||||||||||||||||||
|
Condition33%1/3
$arg->{"_register_stash_method"} ||= sub {
$assembler->register_stash(@_);
}
MC/DC0%0/2
$arg->{"_register_stash_method"} ||= sub {
$assembler->register_stash(@_);
}
$arg->{"_register_stash_method"}
sub {
$assembler->register_stash(@_);
}
Truth table33%1/3
A ||= B
A= $arg->{"_register_stash_method"}B= sub {
$assembler->register_stash(@_);
}
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 2 | return; | |||||||||||||||||||
| 55 | 3 | }; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 1 | ▶ | sub _register_or_retrieve_stash { | ||||||||||||||||||
|
Subroutine
_register_or_retrieve_stash: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 59 | 1 | my ($self, $name) = @_; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | my $stash = $self->zilla->stash_named($name); | |||||||||||||||||||
| 62 | 1 | ▶ | return $stash | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | if $stash; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | # TODO isn't there a better way?! | ||||||||||||||||||||
| 66 | 1 | (my $stash_pkg = $name) =~ s/^%/Dist::Zilla::Stash::/; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | ### $stash_pkg; | ||||||||||||||||||||
| 69 | 1 | Class::Load::load_class($stash_pkg); | |||||||||||||||||||
| 70 | 1 | $stash = $stash_pkg->new(); | |||||||||||||||||||
| 71 | 1 | $self->_register_stash($name => $stash); | |||||||||||||||||||
| 72 | 1 | return $stash; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 3 | !!42; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||