File Coverage

blib/lib/Dist/Zilla/Chrome/Test.pm
Criterion Covered Total %
statement 27 28 96.4
branch 5 6 83.3
condition 2 2 100.0
subroutine 8 9 88.8
pod 0 3 0.0
total 42 48 87.5


line stmt bran cond sub pod time code
1             # ABSTRACT: the chrome used by Dist::Zilla::Tester
2              
3             use Moose;
4 49     49   383  
  49         116  
  49         380  
5             use Dist::Zilla::Pragmas;
6 49     49   347760  
  49         131  
  49         391  
7             use MooseX::Types::Moose qw(ArrayRef HashRef Str);
8 49     49   21861 use Dist::Zilla::Types qw(OneZero);
  49         2314727  
  49         537  
9 49     49   288147 use Log::Dispatchouli 1.102220;
  49         222  
  49         660  
10 49     49   150337  
  49         10808378  
  49         1810  
11             use namespace::autoclean;
12 49     49   463  
  49         126  
  49         499  
13             has logger => (
14             is => 'ro',
15             default => sub {
16             Log::Dispatchouli->new({
17             ident => 'Dist::Zilla::Tester',
18             log_pid => 0,
19             to_self => 1,
20             });
21             }
22             );
23              
24             #pod =attr response_for
25             #pod
26             #pod The response_for attribute (which exists only in the Test chrome) is a
27             #pod hashref that lets you specify the answer to questions asked by
28             #pod C<prompt_str> or C<prompt_yn>. The key is the prompt string. If the
29             #pod value is a string, it is returned every time that question is asked.
30             #pod If the value is an arrayref, the first element is shifted off and
31             #pod returned every time the question is asked. If the arrayref is empty
32             #pod (or the prompt is not listed in the hash), the default answer (if any)
33             #pod is returned.
34             #pod
35             #pod Since you can't pass arguments to the Chrome constructor, response_for
36             #pod is initialized to an empty hash, and you can add entries after
37             #pod construction with the C<set_response_for> method:
38             #pod
39             #pod $chrome->set_response_for($prompt => $response);
40             #pod
41             #pod =cut
42              
43             has response_for => (
44             isa => HashRef[ ArrayRef | Str ],
45             traits => [ 'Hash' ],
46             default => sub { {} },
47             handles => {
48             response_for => 'get',
49             set_response_for => 'set',
50             },
51             );
52              
53             my ($self, $prompt, $arg) = @_;
54             $arg ||= {};
55 15     15 0 3345  
56 15   100     132 my $response = $self->response_for($prompt);
57              
58 15         765 $response = shift @$response if ref $response;
59              
60 15 50       63 $response = $arg->{default} unless defined $response;
61              
62 15 100       77 $self->logger->log_fatal("no response for test prompt '$prompt'")
63             unless defined $response;
64 15 100       116  
65             return $response;
66             }
67 14         309  
68             my $self = shift;
69              
70             return OneZero->coerce( $self->prompt_str(@_) );
71 9     9 0 40 }
72              
73 9         130  
74             with 'Dist::Zilla::Role::Chrome';
75             __PACKAGE__->meta->make_immutable;
76 0     0 0   1;
77              
78              
79             =pod
80              
81             =encoding UTF-8
82              
83             =head1 NAME
84              
85             Dist::Zilla::Chrome::Test - the chrome used by Dist::Zilla::Tester
86              
87             =head1 VERSION
88              
89             version 6.028
90              
91             =head1 PERL VERSION
92              
93             This module should work on any version of perl still receiving updates from
94             the Perl 5 Porters. This means it should work on any version of perl released
95             in the last two to three years. (That is, if the most recently released
96             version is v5.40, then this module should work on both v5.40 and v5.38.)
97              
98             Although it may work on older versions of perl, no guarantee is made that the
99             minimum required version will not be increased. The version may be increased
100             for any reason, and there is no promise that patches will be accepted to lower
101             the minimum required perl.
102              
103             =head1 ATTRIBUTES
104              
105             =head2 response_for
106              
107             The response_for attribute (which exists only in the Test chrome) is a
108             hashref that lets you specify the answer to questions asked by
109             C<prompt_str> or C<prompt_yn>. The key is the prompt string. If the
110             value is a string, it is returned every time that question is asked.
111             If the value is an arrayref, the first element is shifted off and
112             returned every time the question is asked. If the arrayref is empty
113             (or the prompt is not listed in the hash), the default answer (if any)
114             is returned.
115              
116             Since you can't pass arguments to the Chrome constructor, response_for
117             is initialized to an empty hash, and you can add entries after
118             construction with the C<set_response_for> method:
119              
120             $chrome->set_response_for($prompt => $response);
121              
122             =head1 AUTHOR
123              
124             Ricardo SIGNES 😏 <cpan@semiotic.systems>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2022 by Ricardo SIGNES.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut