| 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: Search the configuration of an application | ||||||||||
| 11 | |||||||||||
| 12 | package App::Cme::Command::search ; | ||||||||||
| 13 | 1 | $App::Cme::Command::search::VERSION = '1.049'; | |||||||||
| 14 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use 5.10.1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use App::Cme -command ; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | use base qw/App::Cme::Common/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | use Config::Model::ObjTreeScanner; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 25 | 1 | my ($self, $opt, $args) = @_; | |||||||||
| 26 | 1 | $self->check_unknown_args($args); | |||||||||
| 27 | 1 | $self->process_args($opt,$args); | |||||||||
| 28 | 1 | return; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 1 | my ( $class, $app ) = @_; | |||||||||
| 33 | return ( | ||||||||||
| 34 | [ | ||||||||||
| 35 | 1 | "search=s" => "string or pattern to search in configuration" , | |||||||||
| 36 | { required => 1 } | ||||||||||
| 37 | ], | ||||||||||
| 38 | [ | ||||||||||
| 39 | "narrow-search=s" => "narrows down the search to element, value, key, summary, description or help", | ||||||||||
| 40 | { regex => qr/^(?:element|value|key|summary|description|help|all)$/, default => 'all' } | ||||||||||
| 41 | ], | ||||||||||
| 42 | $class->cme_global_options, | ||||||||||
| 43 | ); | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1 | ▶ | sub usage_desc { | ||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 47 | 1 | my ($self) = @_; | |||||||||
| 48 | 1 | my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o" | |||||||||
| 49 | 1 | return "$desc [application] [ config_file ] -search xxx [ -narrow-search ... ] " ; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub description { | ||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 0 | my ($self) = @_; | |||||||||
| 54 | 0 | return $self->get_documentation; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 58 | 1 | my ($self, $opt, $args) = @_; | |||||||||
| 59 | |||||||||||
| 60 | 1 | my ($model, $inst, $root) = $self->init_cme($opt,$args); | |||||||||
| 61 | |||||||||||
| 62 | 1 | my @res = $root->tree_searcher( type => $opt->{narrow_search} )->search($opt->{search}); | |||||||||
| 63 | 1 | foreach my $path (@res) { | |||||||||
| 64 | 2 | print "$path"; | |||||||||
| 65 | 2 | my $obj = $root->grab($path); | |||||||||
| 66 | 2 | ▶ | if ( $obj->get_type =~ /leaf|check_list/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 2 | my $v = $obj->fetch; | |||||||||
| 68 | 2 | ▶ | $v = defined $v ? $v : '<undef>'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 2 | print " -> '$v'"; | |||||||||
| 70 | } | ||||||||||
| 71 | 2 | print "\n"; | |||||||||
| 72 | } | ||||||||||
| 73 | 1 | return; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | 1; | |||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||