| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of Config-Model-Itself | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2007-2026 by Dominique Dumont. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | package Config::Model::Itself::BackendDetector 2.032; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # since this package is mostly targeted for dev environments | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # let the detector detect models under development | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use feature qw/postderef signatures/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use Pod::POM ; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | extends 'Config::Model::Value' ; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 213 | ▶ | around 'setup_enum_choice' => sub ($orig, $self, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 213 | ▶ | my @input = ref($args[0]) ? $args[0]->@* : @args ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # using a hash to make sure that a backend is not listed twice. This may | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # happen in development environment where a backend is found in /usr/lib | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # and in ./lib (or ./blib) | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 213 | my %choices = map { ($_ => 1);} @input; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # find available backends in all @INC directories | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1920 | ▶ | my $wanted = sub ($path, $) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | # Get the backend file relative to Config/Model/Backend dir | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 1920 | my ($n) = ($path =~ s!.*Backend/!!r); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1920 | ▶ | if ($path->is_file and $n =~ s/\.pm$// and $n !~ /Any$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$path->is_file and $n =~ s/\.pm$//u and not $n =~ /Any$/u
$path->is_file and $n =~ s/\.pm$//u
MC/DC66%2/3
$path->is_file and $n =~ s/\.pm$//u and not $n =~ /Any$/u
$path->is_file
$n =~ s/\.pm$//u
not $n =~ /Any$/u
Truth table75%3/4
A and B and not(C)
A= $path->is_fileB= $n =~ s/\.pm$//uC= not $n =~ /Any$/u
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1706 | $n =~ s!/!::!g ; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1706 | $choices{$n} = 1 ; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 213 | } ; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 213 | foreach my $inc (@INC) { | |||||||||||||||||||||||||||||||||||||||||
| 45 | 2002 | my $path = path($inc)->child("Config/Model/Backend") ; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 2002 | ▶ | $path->visit($wanted, { recurse => 1} ) if $path->is_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 213 | $self->$orig(sort keys %choices) ; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 213 | return; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 213 | ▶ | sub set_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_help: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 213 | my ($self,$args) = @_ ; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 213 | ▶ | my $help = delete $args->{help} || {} ; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'help'} || {}
MC/DC0%0/1
delete $args->{'help'} || {}
delete $args->{'help'}
Truth table50%1/2
A
A= delete $args->{'help'}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 213 | my $path = $INC{"Config/Model.pm"} ; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 213 | $path =~ s!\.pm!/Backend! ; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 213 | my $parser = Pod::POM->new(); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1917 | ▶ | my $wanted = sub ($path, $) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1917 | ▶ | return unless ($path->is_file); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1917 | ▶ | return if $path->basename eq "Any.pm" ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1704 | ▶ | return if $path =~ /Role/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1704 | my $help_key = $path->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 1704 | $help_key =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1704 | $help_key =~ s!/!::!g ; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1704 | my $perl_name = $help_key ; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1704 | $help_key =~ s!.*Backend::!! ; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1704 | $perl_name =~ s!.*Config!Config! ; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1704 | ▶ | my $pom = $parser->parse_file($path->stringify) || die $parser->error(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$parser->parse_file($path->stringify) || die($parser->error)
MC/DC0%0/1
$parser->parse_file($path->stringify) || die($parser->error)
$parser->parse_file($path->stringify)
Truth table50%1/2
A
A= $parser->parse_file($path->stringify)
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1704 | foreach my $head1 ($pom->head1()) { | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1704 | ▶ | if ($head1->title() eq 'NAME') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1704 | my $c = $head1->content(); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1704 | $c =~ s/.*?-\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1704 | $c =~ s/\n//g; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1704 | $help->{$help_key} = $c . " provided by L<$perl_name>"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1704 | last; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 213 | }; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 213 | path($path)->visit ($wanted, {recurse => 1} ) ; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 213 | $self->{help} = $help; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 213 | return; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # ABSTRACT: Detect available read/write backends usable by config models | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||||||||||||||||