| 1 | package Rose::Conf; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.021'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | our $ExportLevel = 0; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub import | ||||||||||||||||||||||||||||
| 12 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=19.7
| |||||||||||||||||||||||||||||
| 13 | 5 | my($pkg, $export_name) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | return unless(@_ > 1 && length $export_name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ > 1 and length $export_name
MC/DC50%1/2
@_ > 1 and length $export_name
@_ > 1
length $export_name
Truth table66%2/3
A and B
A= @_ > 1B= length $export_name
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my($callpkg) = caller($ExportLevel); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | return if($pkg eq __PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | # Mostly lifted from Exporter.pm | ||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Make import warnings look like they're coming from the "use" | ||||||||||||||||||||||||||||
| 26 | local $SIG{'__WARN__'} = sub | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 28 | 0 | my($text) = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if($text =~ s/ at \S*Rose\/Conf.pm line \d+.*\n//) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||
| 32 | 0 | local $Carp::CarpLevel = 1; # ignore package calling us too. | |||||||||||||||||||||||||||
| 33 | 0 | carp $text; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 0 | warn $text; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 2 | }; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | local $SIG{'__DIE__'} = sub | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 43 | 0 | local $Carp::CarpLevel = 1; # ignore package calling us too. | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | Carp::croak "$_[0] Illegal null symbol in \@${1}::EXPORT" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if($_[0] =~ /^Unable to create sub named "(.*?)::"/); | ||||||||||||||||||||||||||||
| 46 | 2 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | ▶ | unless($export_name =~ /^%\w+$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 0 | local $Carp::CarpLevel = 0; | |||||||||||||||||||||||||||
| 51 | 0 | Carp::croak "Usage: use $pkg qw(%SOME_HASH)"; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Chop off the % | ||||||||||||||||||||||||||||
| 55 | 2 | $export_name = substr($export_name, 1); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Alias the %CONF hash | ||||||||||||||||||||||||||||
| 58 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 2 | *{"${callpkg}::$export_name"} = \%{"${pkg}::CONF"} | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub param | ||||||||||||||||||||||||||||
| 63 | 52 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
param: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 52 | my($class) = shift; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 52 | my $conf = $class->conf_hash; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 52 | ▶ | if(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | 52 | my $param = shift; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 52 | ▶ | if(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | 3 | return $conf->{$param} = shift; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | else | ||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | Carp::croak "No such conf parameter in $class: '$param'\n" | ||||||||||||||||||||||||||||
| 79 | 49 | ▶ | unless(exists $conf->{$param}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 45 | ▶ | if(ref $conf->{$param} eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 5 | return bless $conf->{$param}, 'Rose::Conf::Setting'; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 40 | return $conf->{$param}; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | Carp::croak "Cannot get param() without parameter name"; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub conf_hash | ||||||||||||||||||||||||||||
| 94 | 66 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
conf_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 66 | my($class) = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 66 | return \%{$class . '::CONF'}; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub param_exists | ||||||||||||||||||||||||||||
| 103 | 18 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
param_exists: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 18 | my($class, $param) = @_; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 18 | ▶ | Carp::croak "Cannot check if param_exists() without parameter name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | unless(defined $param); | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 18 | my $conf = $class->conf_hash; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 18 | return exists $conf->{$param}; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | BEGIN | ||||||||||||||||||||||||||||
| 115 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | package Rose::Conf::Setting; | ||||||||||||||||||||||||||||
| 117 | 2 | our @ISA = qw(Rose::Conf); | |||||||||||||||||||||||||||
| 118 | 20 | ▶ | sub conf_hash { $_[0] } | ||||||||||||||||||||||||||
|
Subroutine
conf_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 2 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||