| 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: Dump the configuration of an application | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | $App::Cme::Command::dump::VERSION = '1.038'; | 
| 13 |  |  |  |  |  |  | use strict; | 
| 14 | 1 |  |  | 1 |  | 673 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 15 | 1 |  |  | 1 |  | 4 | use 5.10.1; | 
|  | 1 |  |  |  |  | 6 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 16 | 1 |  |  | 1 |  | 8 |  | 
|  | 1 |  |  |  |  | 3 |  | 
| 17 |  |  |  |  |  |  | use App::Cme -command ; | 
| 18 | 1 |  |  | 1 |  | 4 |  | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 19 |  |  |  |  |  |  | use base qw/App::Cme::Common/; | 
| 20 | 1 |  |  | 1 |  | 269 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 83 |  | 
| 21 |  |  |  |  |  |  | use Config::Model::ObjTreeScanner; | 
| 22 | 1 |  |  | 1 |  | 6 | use YAML::PP qw/Dump/; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 23 | 1 |  |  | 1 |  | 460 | use JSON; | 
|  | 1 |  |  |  |  | 49494 |  | 
|  | 1 |  |  |  |  | 54 |  | 
| 24 | 1 |  |  | 1 |  | 8 | use Data::Dumper; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 25 | 1 |  |  | 1 |  | 111 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 437 |  | 
| 26 |  |  |  |  |  |  | my ($self, $opt, $args) = @_; | 
| 27 |  |  |  |  |  |  | $self->check_unknown_args($args); | 
| 28 | 0 |  |  | 0 | 1 |  | $opt->{quiet} = 1; # don't want to mess up yaml output | 
| 29 | 0 |  |  |  |  |  | $self->process_args($opt,$args); | 
| 30 | 0 |  |  |  |  |  | return; | 
| 31 | 0 |  |  |  |  |  | } | 
| 32 | 0 |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | my ( $class, $app ) = @_; | 
| 34 |  |  |  |  |  |  | return ( | 
| 35 |  |  |  |  |  |  | [ | 
| 36 | 0 |  |  | 0 | 1 |  | "dumptype=s" => "Dump all values (full) or only customized values", | 
| 37 |  |  |  |  |  |  | { | 
| 38 |  |  |  |  |  |  | regex => qr/^(?:full|custom|non_upstream_default)$/, | 
| 39 | 0 |  |  |  |  |  | default => 'custom' | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  | ], | 
| 42 |  |  |  |  |  |  | [ | 
| 43 |  |  |  |  |  |  | "format=s" => "dump using specified format (yaml json perl cml)", | 
| 44 |  |  |  |  |  |  | { | 
| 45 |  |  |  |  |  |  | regex => qr/^(?:json|ya?ml|perl|cml|cds)$/i, | 
| 46 |  |  |  |  |  |  | default => 'yaml' | 
| 47 |  |  |  |  |  |  | }, | 
| 48 |  |  |  |  |  |  | ], | 
| 49 |  |  |  |  |  |  | $class->cme_global_options, | 
| 50 |  |  |  |  |  |  | ); | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | my ($self) = @_; | 
| 54 |  |  |  |  |  |  | my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o" | 
| 55 |  |  |  |  |  |  | return "$desc [application]  [ config_file ] [ -dumptype full|custom ] [ path ]"; | 
| 56 |  |  |  |  |  |  | } | 
| 57 | 0 |  |  | 0 | 1 |  |  | 
| 58 | 0 |  |  |  |  |  | my ($self) = @_; | 
| 59 | 0 |  |  |  |  |  | return $self->get_documentation; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | my ($self, $opt, $args) = @_; | 
| 63 | 0 |  |  | 0 | 1 |  |  | 
| 64 | 0 |  |  |  |  |  | my ($model, $inst, $root) = $self->init_cme($opt,$args); | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | my $target_node = $root->grab(step => "@$args", type => 'node'); | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 0 |  |  | 0 | 1 |  | my $dump_string; | 
| 69 |  |  |  |  |  |  | my $format = $opt->{format}; | 
| 70 | 0 |  |  |  |  |  | my $mode = $opt->{dumptype} || 'custom'; | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 0 |  |  |  |  |  | if ($format =~ /cml|cds/i) { | 
| 73 |  |  |  |  |  |  | $dump_string = $target_node->dump_tree( mode => $mode ); | 
| 74 | 0 |  |  |  |  |  | } | 
| 75 | 0 |  |  |  |  |  | else { | 
| 76 | 0 |  | 0 |  |  |  | my $perl_data = $target_node->dump_as_data( | 
| 77 |  |  |  |  |  |  | ordered_hash_as_list => 0, | 
| 78 | 0 | 0 |  |  |  |  | mode => $mode | 
| 79 | 0 |  |  |  |  |  | ); | 
| 80 |  |  |  |  |  |  | $dump_string | 
| 81 |  |  |  |  |  |  | = $format =~ /ya?ml/i ? Dump($perl_data) | 
| 82 | 0 |  |  |  |  |  | : $format =~ /json/i  ? encode_json($perl_data) | 
| 83 |  |  |  |  |  |  | :                       Dumper($perl_data) ; # Perl data structure | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  | print $dump_string ; | 
| 86 | 0 | 0 |  |  |  |  | return; | 
|  |  | 0 |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | 1; | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 0 |  |  |  |  |  |  | 
| 92 | 0 |  |  |  |  |  | =pod | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =encoding UTF-8 | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 NAME | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | App::Cme::Command::dump - Dump the configuration of an application | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 VERSION | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | version 1.038 | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | # dump ~/.ssh/config in cme syntax | 
| 107 |  |  |  |  |  |  | # (this example requires Config::Model::OpenSsh) | 
| 108 |  |  |  |  |  |  | $ cme dump -format cml ssh | 
| 109 |  |  |  |  |  |  | Host:"*" - | 
| 110 |  |  |  |  |  |  | Host:"*.debian.org" | 
| 111 |  |  |  |  |  |  | User=dod - | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | Dump configuration content on STDOUT with YAML format. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | By default, dump only custom values, i.e. different from application | 
| 118 |  |  |  |  |  |  | built-in values or model default values. You can use the C<-dumptype> option for | 
| 119 |  |  |  |  |  |  | other types of dump: | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | -dumptype [ full | custom | non_upstream_default ] | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | Choose to dump every values (full), or only customized values (default) | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | C<non_upstream_default> is like C<full> mode, but value identical with | 
| 126 |  |  |  |  |  |  | application default are omitted. But this should seldom happen. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | By default, dump in yaml format. This can be changed in C<json>, | 
| 129 |  |  |  |  |  |  | C<perl>, C<cml> (aka L<Config::Model::Loader> format, C<cds> is also | 
| 130 |  |  |  |  |  |  | accepted) with C<-format> option. | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head1 Common options | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | See L<cme/"Global Options">. | 
| 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 |