| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # $Id: Info.pm,v 1.4 2005/02/02 20:43:45 eserte Exp $ | ||||||||||||||||||||||||||||
| 5 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Copyright (C) 2005 Slaven Rezic. All rights reserved. | ||||||||||||||||||||||||||||
| 8 | # This package is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 9 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # Mail: slaven@rezic.de | ||||||||||||||||||||||||||||
| 12 | # WWW: http://www.rezic.de/eserte/ | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | package WE::DB::Info; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | __PACKAGE__->mk_accessors(qw(Info File)); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Cwd qw(cwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use File::Basename qw(dirname); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use YAML (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | my($class, %args) = @_; | |||||||||||||||||||||||||||
| 31 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (!exists $args{File}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | $args{File} = File::Spec->catfile(cwd, "INFO.yml"); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | while(my($k,$v) = each %args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | $self->$k($v); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | $self; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 0 | local $^W = undef; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $info = eval { YAML::LoadFile($self->File) } || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
YAML::LoadFile($self->File)
}
} || {}
MC/DC0%0/1
eval {
do {
YAML::LoadFile($self->File)
}
} || {}
eval {
do {
YAML::LoadFile($self->File)
}
}
Truth table0%0/2
A
A= eval {
do {
YAML::LoadFile($self->File)
}
}
| |||||||||||||||||||||||||||||
| 45 | 0 | $self->Info($info); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub getopt { | ||||||||||||||||||||||||||
|
Subroutine
getopt: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||
| 50 | 0 | my $info = $self->Info; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $make_abs = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 53 | 0 | my $f = shift; | |||||||||||||||||||||||||||
| 54 | 0 | File::Spec->rel2abs($f, dirname($self->File)); | |||||||||||||||||||||||||||
| 55 | 0 | }; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my %opt; | |||||||||||||||||||||||||||
| 58 | 0 | for my $def ('inc@,abs', 'datadir,abs', | |||||||||||||||||||||||||||
| 59 | qw(rootclass | ||||||||||||||||||||||||||||
| 60 | userdbclass userdbclass_file | ||||||||||||||||||||||||||||
| 61 | objdbclass objdbclass_file)) { | ||||||||||||||||||||||||||||
| 62 | 0 | my($key, $sigil, $attribs) = $def =~ m{^(.*?)([\@\$\%])?(,.*)?$}; | |||||||||||||||||||||||||||
| 63 | 0 | my %attribs; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($attribs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | %attribs = map {($_,1)} split /,/, substr($attribs, 1); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (exists $info->{$key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($sigil && $sigil eq '@') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sigil and $sigil eq "\@"
MC/DC0%0/2
$sigil and $sigil eq "\@"
$sigil
$sigil eq "\@"
Truth table0%0/3
A and B
A= $sigilB= $sigil eq "\@"
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (UNIVERSAL::isa($info->{$key}, "ARRAY")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $opt{$key} = $info->{$key}; | |||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||
| 72 | 0 | $opt{$key} = [ $info->{$key} ]; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($attribs{'abs'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | for (@{$opt{$key}}) { | |||||||||||||||||||||||||||
| 76 | 0 | $_ = $make_abs->($_); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||
| 80 | 0 | $opt{$key} = $info->{$key}; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($attribs{'abs'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $opt{$key} = $make_abs->($opt{$key}); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | %opt; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||