| 1 | ## -*- Mode: CPerl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## File: DTA::CAB::Format::Registry.pm | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Description: registry for I/O formats | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | package DTA::CAB::Format::Registry; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use DTA::CAB::Persistent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use DTA::CAB::Logger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ## Globals | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our @ISA = qw(DTA::CAB::Persistent DTA::CAB::Logger); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | *isa = \&UNIVERSAL::isa; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | *can = \&UNIVERSAL::can; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ## Constructors etc. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | ## $reg = DTA::CAB::Format::Registry->new(%args) | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ## + %$obj, %args: | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ## ( | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ## reg => [\%classReg, ...], ##-- registered classes | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ## short2reg => {$short=>\%classReg, ...}, ##-- short names to registry entries | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ## base2reg => {$base =>\%classReg, ...}, ##-- base names to registry entries | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ## ) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | ## + each \%classReg is a HASH-ref of the form: | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ## { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ## name => $basename, ##-- basename for the class (package name) | ||||||||||||||||||||||||||||||||||||||||||
| 38 | ## short => $shortname, ##-- short name for the class (default = package name suffix, lower-cased) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ## readerClass => $readerClass, ##-- default: $base | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ## writerClass => $writerClass, ##-- default: $base | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ## readerOpts => \%readerOpts, ##-- default: none | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ## writerOpts => \%writerOpts, ##-- default: none | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ## opts => \%commonOpts, ##-- default: none | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ## filenameRegex => $regex, ##-- filename regex for guessFilename() | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ## } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my $reg = bless({ | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | reg => [], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | short2reg => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | base2reg => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | }, ref($that)||$that); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | $reg->refresh(); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | return $reg; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | ## $reg = $reg->clear() | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ## + clears the registry | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my $reg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | @{$reg->{reg}} = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | %{$reg->{short2reg}} = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | %{$reg->{base2reg}} = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | return $reg; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | ## $reg = $reg->refresh(); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ## + re-registers all formats in $reg->{reg} | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub refresh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my $reg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my @creg = @{$reg->{reg}}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | $reg->clear(); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | $reg->register(%$_) foreach (reverse @creg); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | return $reg; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | ## $reg = $reg->compile(%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ## + adds following keys to each registry item \%classReg: | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ## ( | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ## reader => $readerObj, ##-- = $classReg{readerClass}->new($reg->readerOpts($classReg,%opts)) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ## writer => $writerObj, ##-- = $classReg{writerClass}->new($reg->writerOpts($classReg,%opts)) | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ## ) | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub compile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $reg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | foreach (@{$reg->{reg}}) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $_->{reader} = $_->{readerClass}->new($reg->readerOpts($_),@_) if (can($_->{readerClass},'new')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $_->{writer} = $_->{writerClass}->new($reg->writerOpts($_),@_) if (can($_->{writerClass},'new')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return $reg; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | ## \%classReg = $reg->register(%classReg) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ## + %classReg: | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ## ( | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ## name => $basename, ##-- basename for the class (package name): REQUIRED | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ## short => $shortname, ##-- short name for the class (default = package name suffix, lower-cased) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ## readerClass => $readerClass, ##-- default: $base | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ## writerClass => $writerClass, ##-- default: $base | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ## readerOpts => \%readerOpts, ##-- default: none | ||||||||||||||||||||||||||||||||||||||||||
| 101 | ## writerOpts => \%writerOpts, ##-- default: none | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ## opts => \%commonOpts, ##-- default: none | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ## filenameRegex => $regex, ##-- filename regex for guessFilenameFormat() | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ## ) | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 23 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 23 | my ($reg,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 23 | ▶ | if (!defined($opts{name})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $reg->logwarn("register(): 'name' key required!"); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 23 | ▶ | $opts{readerClass} = $opts{name} if (!defined($opts{readerClass})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 23 | ▶ | $opts{writerClass} = $opts{name} if (!defined($opts{writerClass})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 23 | ▶ | if (!defined($opts{short})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 9 | $opts{short} = lc($opts{name}); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 9 | $opts{short} =~ s/.*\:\://; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 23 | my $creg = {%opts}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 23 | unshift(@{$reg->{reg}}, $creg); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 23 | $reg->{short2reg}{$opts{short}} = $creg; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 23 | $reg->{base2reg}{$opts{name}} = $creg; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 23 | return $creg; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | ##============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ## Methods: Access | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | ## \%classReg_or_undef = $reg->lookup(%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ## + Get the most recently registered entry for %opts, which may contain | ||||||||||||||||||||||||||||||||||||||||||
| 131 | ## (in order of decreasing priority): | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ## class => $class, ##-- short name, basename, or "DTA::CAB::Format::" suffix | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ## file => $filename, ##-- attempt to guess format from $filename | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub lookup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my ($reg,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (defined($opts{class})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | ##-- lookup: by class name | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $class = $opts{class}; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | return $reg->{short2reg}{$class} if ($reg->{short2reg}{$class}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return $reg->{short2reg}{lc($class)} if ($reg->{short2reg}{lc($class)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return $reg->{base2reg}{$class} if ($reg->{base2reg}{$class}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $class = "DTA::CAB::Format::${class}" if (!isa($class,'DTA::CAB::Format')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | #$that->logconfess("lookup(): unknown format class '$class'") if (!isa($class,'DTA::CAB::Format')); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return $reg->{base2reg}{$class} if ($reg->{base2reg}{$class}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif (defined($opts{file})) { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $filename = $opts{file}; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | foreach (@{$reg->{reg}}) { | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | return $_ if (defined($_->{filenameRegex}) && $filename =~ $_->{filenameRegex}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_->{"filenameRegex"} and $filename =~ /$_->{"filenameRegex"}/
MC/DC0%0/2
defined $_->{"filenameRegex"} and $filename =~ /$_->{"filenameRegex"}/
defined $_->{"filenameRegex"}
$filename =~ /$_->{"filenameRegex"}/
Truth table0%0/3
A and B
A= defined $_->{"filenameRegex"}B= $filename =~ /$_->{"filenameRegex"}/
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | ## $fmt = $reg->newFormat($class_or_short_or_suffix, %opts) | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ## + creates a new format of the registered base class matching $class_or_short_or_suffix; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ## backwards-compatible | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub newFormat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newFormat: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my ($reg,$class,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $creg = $reg->lookup(class=>$class,%opts); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return undef if (!defined($creg)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return $creg->{name}->new($reg->commonOpts($creg),%opts); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | ## %opts = $reg->commonOpts($creg) | ||||||||||||||||||||||||||||||||||||||||||
| 167 | ## + common class options | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub commonOpts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commonOpts: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | #my ($reg,$creg) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return $_[1]{opts} ? %{$_[1]{opts}} : qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | ## %opts = $reg->readerOpts($creg) | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub readerOpts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readerOpts: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return ($_[0]->commonOpts($_[1]), ($_[1]{readerOpts} ? %{$_[1]{readerOpts}} : qw())); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | ## %opts = $reg->writerOpts($creg) | ||||||||||||||||||||||||||||||||||||||||||
| 179 | ## %opts = $reg->readerOpts($creg) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub writerOpts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writerOpts: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return ($_[0]->commonOpts($_[1]), ($_[1]{writerOpts} ? %{$_[1]{writerOpts}} : qw())); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | ## $class_or_undef = $reg->readerClass($class_or_short_or_suffix,%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ## + get registered reader class for $class_or_short_or_suffix; accepts $opts{file} | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub readerClass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readerClass: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my ($reg,$class,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $creg = $reg->lookup(class=>$class,%opts); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return $creg ? $creg->{readerClass} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | ## $class_or_undef = $reg->writerClass($class_or_short_or_suffix,%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 193 | ## + get registered writer class for $class_or_short_or_suffix; accepts $opts{file} | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub writerClass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writerClass: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my ($reg,$class,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $creg = $reg->lookup(class=>$class,%opts); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return $creg ? $creg->{writerClass} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | ## $class_or_undef = $reg->formatClass($class_or_short_or_suffix,%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 201 | ## + get registered common reader/writer class for $class_or_short_or_suffix; accepts $opts{file} | ||||||||||||||||||||||||||||||||||||||||||
| 202 | ## + returns undef if reader and writer classes for $class_or_short_or_suffix are distinct; accepts $opts{file} | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub formatClass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
formatClass: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($reg,$class,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $creg = $reg->lookup(class=>$class,%opts); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return $creg->{readerClass} if ($creg && ($creg->{readerClass}//'') eq ($creg->{writerClass}//'')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/7
$creg and ($creg->{"readerClass"} // "") eq ($creg->{"writerClass"} // "")
$creg->{"readerClass"} // ""
$creg->{"writerClass"} // ""
MC/DC0%0/2
$creg and ($creg->{"readerClass"} // "") eq ($creg->{"writerClass"} // "")
$creg
$creg->{"readerClass"}
MC/DC0%0/1
$creg->{"writerClass"} // ""
$creg->{"writerClass"}
Truth table0%0/3
A and B
A= $cregB= $creg->{"readerClass"}
Truth table0%0/2
A
A= $creg->{"writerClass"}
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | ## $fmt = $reg->newReader(%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 211 | ## + %opts may contain any %lookup options (class,file), and are | ||||||||||||||||||||||||||||||||||||||||||
| 212 | ## otherwise passed to CLASS->new() | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub newReader { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newReader: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my ($reg,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $creg = $reg->lookup(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return undef if (!defined($creg)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | delete @opts{qw(class file)}; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | return $creg->{readerClass}->new($reg->readerOpts($creg),%opts); | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | ## $fmt = $reg->newWriter(%opts) | ||||||||||||||||||||||||||||||||||||||||||
| 222 | ## + special %opts: | ||||||||||||||||||||||||||||||||||||||||||
| 223 | ## class => $class, ##-- classname or DTA::CAB::Format suffix | ||||||||||||||||||||||||||||||||||||||||||
| 224 | ## file => $filename, ##-- attempt to guess format from filename | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub newWriter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newWriter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my ($reg,%opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $creg = $reg->lookup(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return undef if (!defined($creg)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | delete @opts{qw(class file)}; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return $creg->{writerClass}->new($reg->writerOpts($creg),%opts); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | ## $readerClass_or_undef = $CLASS_OR_OBJ->fileReaderClass($filename) | ||||||||||||||||||||||||||||||||||||||||||
| 234 | ## + backkwards-compatible wrapper for lookup(); attempts to guess reader class name from $filename | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub fileReaderClass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fileReaderClass: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my ($reg,$filename) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $creg = $reg->lookup(file=>$filename); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return defined($creg) ? $creg->{readerClass} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | ## $readerClass_or_undef = $CLASS_OR_OBJ->fileWriterClass($filename) | ||||||||||||||||||||||||||||||||||||||||||
| 242 | ## + backwards-compatible wrapper for lookup(); attempts to guess writer class name from $filename | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub fileWriterClass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fileWriterClass: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my ($reg,$filename) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $creg = $reg->lookup(file=>$filename); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | return defined($creg) ? $creg->{writerClass} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | ## \%classReg_or_undef = $reg->guessFilenameFormat($filename) | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ## + backwards-compatible wrapper for $reg->lookup(file=>$filename) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub guessFilenameFormat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
guessFilenameFormat: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my ($reg,$file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return $reg->lookup(file=>$file); | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | ## \%classReg_or_undef = $reg->short2reg($shortname) | ||||||||||||||||||||||||||||||||||||||||||
| 257 | ## + gets registry entry for short name $shortname | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub short2reg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
short2reg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | return $_[0]{short2reg}{$_[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | ## \%classReg_or_undef = $reg->base2reg($basename) | ||||||||||||||||||||||||||||||||||||||||||
| 263 | ## + gets registry entry for class basename $basename | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub base2reg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base2reg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return $_[0]{base2reg}{$_[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | ##======================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 269 | ## Storable stuff | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | ## ($serialized, $ref1, ...) = $obj->STORABLE_freeze($cloning) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub STORABLE_freeze { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my ($obj,$cloning) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | return ('',[map { {%$_,(defined($_->{filenameRegex}) ? (filenameRegex=>"$_->{filenameRegex}") : qw())} } @{$obj->{reg}}]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | ## $obj = STORABLE_thaw($obj, $cloning, $serialized, $ref1,...) | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub STORABLE_thaw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my ($obj,$cloning,$ser,$classes) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $obj->clear(); | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | @{$obj->{reg}} = @$classes; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $obj->refresh(); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | 1; ##-- be happy | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | __END__ | ||||||||||||||||||||||||||||||||||||||||||