| 1 | # vim: set ts=2 sts=2 sw=2 expandtab smarttab: | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # This file is part of Dist-Zilla-Role-Stash-Plugins | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # This software is copyright (c) 2010 by Randy Stauner. | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 9 | # | ||||||||||||||||||||
| 10 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | package Dist::Zilla::Role::Stash::Plugins; | ||||||||||||||||||||
| 14 | { | ||||||||||||||||||||
| 15 | 3 | $Dist::Zilla::Role::Stash::Plugins::VERSION = '1.006'; | |||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | # git description: v1.005-2-g3d6e9bb | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 3 | $Dist::Zilla::Role::Stash::Plugins::AUTHORITY = 'cpan:RWSTAUNER'; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | # ABSTRACT: A Stash that stores arguments for plugins | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 3 | ▶ | use Config::MVP::Slicer (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 3 | with qw( | |||||||||||||||||||
| 27 | Dist::Zilla::Role::DynamicConfig | ||||||||||||||||||||
| 28 | Dist::Zilla::Role::Stash | ||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # we could define a 'plugged' module attribute and create a generic | ||||||||||||||||||||
| 32 | # method like sub expand_package { $_[0]->plugged_module->expand_package($_[1]) } | ||||||||||||||||||||
| 33 | # but this is a Role (not an actual stash) and is that really useful? | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 3 | requires 'expand_package'; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 3 | has argument_separator => ( | |||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||
| 40 | isa => 'Str', | ||||||||||||||||||||
| 41 | # "Module::Name:variable" "-Plugin/variable" | ||||||||||||||||||||
| 42 | default => '(.+?)\W+(\w+)', | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | # _config inherited | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | has slicer => ( | ||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||
| 51 | isa => 'Config::MVP::Slicer', | ||||||||||||||||||||
| 52 | lazy => 1, | ||||||||||||||||||||
| 53 | 3 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 3 | my $self = shift; | |||||||||||||||||||
| 55 | Config::MVP::Slicer->new({ | ||||||||||||||||||||
| 56 | config => $self->_config, | ||||||||||||||||||||
| 57 | separator => $self->argument_separator, | ||||||||||||||||||||
| 58 | 67 | ▶ | match_package => sub { $self->expand_package($_[0]) eq $_[1] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 59 | }) | ||||||||||||||||||||
| 60 | 3 | }, | |||||||||||||||||||
| 61 | 3 | ); | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 13 | ▶ | sub get_stashed_config { | ||||||||||||||||||
|
Subroutine
get_stashed_config: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 65 | 13 | my ($self, $plugin) = @_; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # TODO: should we compare liberal argument_separator to strict one and warn if not matched? | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 13 | return $self->slicer->slice($plugin); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 7 | ▶ | sub merge_stashed_config { | ||||||||||||||||||
|
Subroutine
merge_stashed_config: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 74 | 7 | my ($self, $plugin, $opts) = @_; | |||||||||||||||||||
| 75 | 7 | ▶ | $opts ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$opts ||= {}
MC/DC100%1/1
$opts ||= {}
$opts
Truth table100%2/2
A
A= $opts
| |||||||||||||||||||||
| 76 | 7 | ▶ | $opts->{stashed} ||= $self->get_stashed_config($plugin); | ||||||||||||||||||
|
Condition66%2/3
$opts->{"stashed"} ||= $self->get_stashed_config($plugin)
MC/DC0%0/2
$opts->{"stashed"} ||= $self->get_stashed_config($plugin)
$opts->{"stashed"}
$self->get_stashed_config($plugin)
Truth table66%2/3
A ||= B
A= $opts->{"stashed"}B= $self->get_stashed_config($plugin)
| |||||||||||||||||||||
| 77 | 7 | $opts->{slice} = delete $opts->{stashed}; | |||||||||||||||||||
| 78 | 7 | return $self->slicer->merge($plugin, $opts); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | # this is a class method required by Dist::Zilla::Role::DynamicConfig | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 3 | ▶ | sub separate_local_config { | ||||||||||||||||||
|
Subroutine
separate_local_config: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 85 | 3 | my ($self, $config) = @_; | |||||||||||||||||||
| 86 | # keys for other plugins should include non-word characters | ||||||||||||||||||||
| 87 | # (like "-Plugin::Name:variable"), so any keys that are only | ||||||||||||||||||||
| 88 | # word characters (valid identifiers) are for this object. | ||||||||||||||||||||
| 89 | 3 | my @local = grep { /^\w+$/ } keys %$config; | |||||||||||||||||||
| 90 | 3 | my %other; | |||||||||||||||||||
| 91 | 3 | ▶ | @other{@local} = delete @$config{@local} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | if @local; | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 3 | return \%other; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 3 | ▶ | no Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 98 | 3 | 1; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||