| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # This file is part of App-Cme | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>. | 
| 5 |  |  |  |  |  |  | # | 
| 6 |  |  |  |  |  |  | # This is free software, licensed under: | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | #   The GNU Lesser General Public License, Version 2.1, February 1999 | 
| 9 |  |  |  |  |  |  | # | 
| 10 |  |  |  |  |  |  | # ABSTRACT: Check the configuration of an application | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | $App::Cme::Command::check::VERSION = '1.038'; | 
| 13 |  |  |  |  |  |  | use strict; | 
| 14 | 1 |  |  | 1 |  | 17025 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 15 | 1 |  |  | 1 |  | 4 | use 5.10.1; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 16 | 1 |  |  | 1 |  | 16 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 17 |  |  |  |  |  |  | use App::Cme -command ; | 
| 18 | 1 |  |  | 1 |  | 5 |  | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 10 |  | 
| 19 |  |  |  |  |  |  | use base qw/App::Cme::Common/; | 
| 20 | 1 |  |  | 1 |  | 376 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 474 |  | 
| 21 |  |  |  |  |  |  | use Config::Model::ObjTreeScanner; | 
| 22 | 1 |  |  | 1 |  | 6 |  | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 338 |  | 
| 23 |  |  |  |  |  |  | my ($self, $opt, $args) = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 2 |  |  | 2 | 1 | 4760 | $self->check_unknown_args($args); | 
| 26 |  |  |  |  |  |  | $self->process_args($opt,$args); | 
| 27 | 2 |  |  |  |  | 10 | return; | 
| 28 | 2 |  |  |  |  | 9 | } | 
| 29 | 2 |  |  |  |  | 4 |  | 
| 30 |  |  |  |  |  |  | my ( $class, $app ) = @_; | 
| 31 |  |  |  |  |  |  | return ( | 
| 32 |  |  |  |  |  |  | [ "strict!" => "cme will exit 1 if warnings are found during check" ], | 
| 33 | 2 |  |  | 2 | 1 | 6 | $class->cme_global_options, | 
| 34 |  |  |  |  |  |  | ); | 
| 35 | 2 |  |  |  |  | 15 | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | my ($self) = @_; | 
| 38 |  |  |  |  |  |  | my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o" | 
| 39 |  |  |  |  |  |  | return "$desc [application]  [ config_file ]"; | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 2 |  |  | 2 | 1 | 3692 |  | 
| 42 | 2 |  |  |  |  | 13 | my ($self) = @_; | 
| 43 | 2 |  |  |  |  | 46 | return $self->get_documentation; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | my ($self, $opt, $args) = @_; | 
| 47 | 0 |  |  | 0 | 1 | 0 |  | 
| 48 | 0 |  |  |  |  | 0 | my ($model, $inst, $root) = $self->init_cme($opt,$args); | 
| 49 |  |  |  |  |  |  | my $check =  $opt->{force_load} ? 'no' : 'yes' ; | 
| 50 |  |  |  |  |  |  | say "Loading data..." if $opt->{verbose}; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 2 |  |  | 2 | 1 | 24 | Config::Model::ObjTreeScanner->new( | 
| 53 |  |  |  |  |  |  | leaf_cb => sub { }, | 
| 54 | 2 |  |  |  |  | 12 | check => $check, | 
| 55 | 2 | 50 |  |  |  | 10549 | )->scan_node( undef, $root ); | 
| 56 | 2 | 100 |  |  |  | 13 |  | 
| 57 |  |  |  |  |  |  | say "Checking data.." if $opt->{verbose}; | 
| 58 |  |  |  |  |  |  | $root->dump_tree( mode => 'full' ); # light check (value per value) | 
| 59 |  |  |  | 18 |  |  | $root->deep_check; # consistency check | 
| 60 | 2 |  |  |  |  | 43 | say "Check done." if $opt->{verbose}; | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | my $ouch = $inst->has_warning; | 
| 63 | 2 | 100 |  |  |  | 49 |  | 
| 64 | 2 |  |  |  |  | 26 | if ( $ouch ) { | 
| 65 | 2 |  |  |  |  | 7523 | my $app = $inst->application; | 
| 66 | 2 | 100 |  |  |  | 2011 | warn "you can try 'cme fix $app' to fix the warnings shown above\n"; | 
| 67 |  |  |  |  |  |  | die "Found $ouch warnings in strict mode\n" if $opt->{strict}; | 
| 68 | 2 |  |  |  |  | 21 | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 2 | 50 |  |  |  | 2489 | return; | 
| 71 | 0 |  |  |  |  | 0 | } | 
| 72 | 0 |  |  |  |  | 0 |  | 
| 73 | 0 | 0 |  |  |  | 0 | 1; | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 2 |  |  |  |  | 57 | =pod | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =encoding UTF-8 | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =head1 NAME | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | App::Cme::Command::check - Check the configuration of an application | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head1 VERSION | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | version 1.038 | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | # standard usage | 
| 91 |  |  |  |  |  |  | cme check popcon | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | # read data from arbitrary file (with Config::Model::Dpkg) | 
| 94 |  |  |  |  |  |  | cme check dpkg-copyright path/to/file | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | Checks the content of the configuration file of an application. Prints warnings | 
| 99 |  |  |  |  |  |  | and errors on STDOUT. | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | Example: | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | cme check fstab | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | Some applications allows one to override the default configuration file. | 
| 106 |  |  |  |  |  |  | For instance, with Debian copyright model, you can run cme on a different file: | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | cme check dpkg-copyright foobar | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | or directly check copyright data on STDIN: | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | curl http://metadata.ftp-master.debian.org/changelogs/main/f/frozen-bubble/unstable_copyright \ | 
| 113 |  |  |  |  |  |  | | cme check dpkg-copyright - | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =head1 Common options | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | See L<cme/"Global Options">. | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head1 options | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =over | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =item -strict | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | When set, cme exits 1 if warnings are found. By default, C<cme> exits | 
| 126 |  |  |  |  |  |  | 0 when warnings are found. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =back | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head1 EXIT CODE | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | cme exits 0 when no errors are found. Exit 1 otherwise. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | If C<-strict> option is set, cme exits 1 when warnings are found. | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | L<cme> | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =head1 AUTHOR | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | Dominique Dumont | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>. | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | This is free software, licensed under: | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | The GNU Lesser General Public License, Version 2.1, February 1999 | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =cut |