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