blib/lib/Langertha/Knarr/CLI/Role/GlobalOptions.pm

filter: Statementstmt 100% 14 / 14 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 100% 24 / 24 CC 3 SCAR 5.1
CC
3
Cov
100%
config_file
2.0
verbose_enabled
2.0
BEGIN
1.0
CRAP 1.7
« blib/lib/Langertha/Knarr/Handler/Raider.pm ↑ Summary blib/lib/Langertha/Knarr/Handler/Code.pm »
1 package Langertha::Knarr::CLI::Role::GlobalOptions;
2 50 our $VERSION = '1.102';
3 # ABSTRACT: Accept knarr's global -c/-v options after the subcommand too
4 50 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use MooX::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 50 option config => (
9 is => 'ro',
10 format => 's',
11 short => 'c',
12 doc => 'Config file path (default: ./knarr.yaml)',
13 predicate => 'has_config',
14 );
15  
16  
17 50 option verbose => (
18 is => 'ro',
19 short => 'v',
20 doc => 'Enable verbose logging (or set KNARR_DEBUG=1)',
21 negatable => 1,
22 predicate => 'has_verbose',
23 );
24  
25  
26 48 ▶sub config_file {
Subroutine config_file: called CC=2 SCAR=6.9
Pod documented
27 48 my ( $self, $chain ) = @_;
28 48 ▶ return $self->has_config ? $self->config : $chain->[0]->config;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_config ? : 26 22 48
29 }
30  
31  
32 43 ▶sub verbose_enabled {
Subroutine verbose_enabled: called CC=2 SCAR=6.9
Pod documented
33 43 my ( $self, $chain ) = @_;
34 43 ▶ return $self->has_verbose ? $self->verbose : $chain->[0]->verbose;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_verbose ? : 7 36 43
35 }
36  
37  
38 50 1;
39  
40 __END__
41  
42 =pod
43  
44 =encoding UTF-8
45  
46 =head1 NAME
47  
48 Langertha::Knarr::CLI::Role::GlobalOptions - Accept knarr's global -c/-v options after the subcommand too
49  
50 =head1 VERSION
51  
52 version 1.102
53  
54 =head1 DESCRIPTION
55  
56 L<MooX::Cmd> hands every argument before the subcommand name to
57 L<Langertha::Knarr::CLI> and every argument after it to the subcommand, so
58 the global C<-c>/C<--config> and C<-v>/C<--verbose> options would only work
59 in front of the subcommand (C<knarr -c prod.yaml start>). Composing this
60 role into a subcommand declares the same two options there as well, so the
61 documented form C<knarr start -c prod.yaml -v> works too.
62  
63 A value given after the subcommand wins over one given before it. Commands
64 read the effective values through L</config_file> and L</verbose_enabled>,
65 never through the global object directly.
66  
67 =head2 --config
68  
69 Same as the global C<-c>/C<--config>, accepted after the subcommand.
70  
71 =head2 --verbose
72  
73 Same as the global C<-v>/C<--verbose>, accepted after the subcommand.
74 C<--no-verbose> switches it off again, also against C<KNARR_DEBUG=1>.
75  
76 =head2 config_file
77  
78 my $file = $self->config_file($chain);
79  
80 Returns the config file path: the subcommand's own C<--config> when given,
81 otherwise the global one from the first element of the L<MooX::Cmd> command
82 chain (which carries the C<./knarr.yaml> default).
83  
84 =head2 verbose_enabled
85  
86 Log::Any::Adapter->set( 'Stderr',
87 log_level => $self->verbose_enabled($chain) ? 'trace' : 'warning' );
88  
89 Returns whether verbose logging is on: the subcommand's own
90 C<--verbose>/C<--no-verbose> when given, otherwise the global setting.
91  
92 =head1 SUPPORT
93  
94 =head2 Issues
95  
96 Please report bugs and feature requests on GitHub at
97 L<https://github.com/Getty/langertha-knarr/issues>.
98  
99 =head2 IRC
100  
101 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
102  
103 =head1 CONTRIBUTING
104  
105 Contributions are welcome! Please fork the repository and submit a pull request.
106  
107 =head1 AUTHOR
108  
109 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
110  
111 =head1 COPYRIGHT AND LICENSE
112  
113 This software is copyright (c) 2026 by Torsten Raudssus.
114  
115 This is free software; you can redistribute it and/or modify it under
116 the same terms as the Perl 5 programming language system itself.
117  
118 =cut
« blib/lib/Langertha/Knarr/Handler/Raider.pm ↑ Summary blib/lib/Langertha/Knarr/Handler/Code.pm »