| 1 | #-*- Mode: CPerl -*- | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | ## File: DDC::Format.pm | ||||||||||||||||||||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||||||||||||||||||||
| 5 | ## Description: | ||||||||||||||||||||
| 6 | ## + DDC Query utilities: output formatting | ||||||||||||||||||||
| 7 | ##====================================================================== | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | package DDC::Format; | ||||||||||||||||||||
| 10 | 26 | ▶ | use IO::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 26 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 26 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | ##====================================================================== | ||||||||||||||||||||
| 15 | ## Globals | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | ##====================================================================== | ||||||||||||||||||||
| 18 | ## Constructors, etc. | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | ## $fmt = $CLASS_OR_OBJ->new(%args) | ||||||||||||||||||||
| 21 | ## + %args: | ||||||||||||||||||||
| 22 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 23 | 0 | my $that = shift; | |||||||||||||||||||
| 24 | 0 | ▶ | return bless { @_ }, ref($that)||$that; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | ## $fmt = $fmt->reset() | ||||||||||||||||||||
| 28 | ## + reset counters, etc. | ||||||||||||||||||||
| 29 | 0 | ▶ | sub reset { return $_[0]; } | ||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | ##====================================================================== | ||||||||||||||||||||
| 32 | ## API | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | ## $str = $fmt->toString($hitList) | ||||||||||||||||||||
| 35 | 0 | ▶ | sub toString { | ||||||||||||||||||
|
Subroutine
toString: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 36 | 0 | my ($fmt,$hits) = @_; | |||||||||||||||||||
| 37 | 0 | return "$hits"; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | ## undef = $fmt->toFile($hitList,$file) | ||||||||||||||||||||
| 41 | ## + default implementation calls $fmt->toFh() | ||||||||||||||||||||
| 42 | 0 | ▶ | sub toFile { | ||||||||||||||||||
|
Subroutine
toFile: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 43 | 0 | my ($fmt,$hits,$file) = @_; | |||||||||||||||||||
| 44 | 0 | ▶ | my $fh = ref($file) ? $file : IO::File->new(">$file"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | ▶ | confess(ref($fmt)."::toFile(): open failed for '$file': $!") if (!$fh); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | my $rc = $fmt->toFh($hits,$fh); | |||||||||||||||||||
| 47 | 0 | ▶ | $fh->close() if (!ref($file)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | return $rc; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | ## undef = $fmt->toFh($hitList,$fh) | ||||||||||||||||||||
| 52 | ## + default implementation calls $fmt->toString() | ||||||||||||||||||||
| 53 | 0 | ▶ | sub toFh { | ||||||||||||||||||
|
Subroutine
toFh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 54 | 0 | my ($fmt,$hits,$fh) = @_; | |||||||||||||||||||
| 55 | 0 | $fh->print($fmt->toString($hits)); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 26 | 1; ##-- be happy | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||