| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #-*- Mode: CPerl -*- | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | ## File: DDC::Format.pm | 
| 4 |  |  |  |  |  |  | ## Author: Bryan Jurish | 
| 5 |  |  |  |  |  |  | ## Description: | 
| 6 |  |  |  |  |  |  | ##  + DDC Query utilities: output formatting | 
| 7 |  |  |  |  |  |  | ##====================================================================== | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | package DDC::Format; | 
| 10 | 26 |  |  | 26 |  | 228 | use IO::File; | 
|  | 26 |  |  |  |  | 55 |  | 
|  | 26 |  |  |  |  | 3443 |  | 
| 11 | 26 |  |  | 26 |  | 181 | use Carp; | 
|  | 26 |  |  |  |  | 83 |  | 
|  | 26 |  |  |  |  | 1206 |  | 
| 12 | 26 |  |  | 26 |  | 205 | use strict; | 
|  | 26 |  |  |  |  | 60 |  | 
|  | 26 |  |  |  |  | 7203 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | ##====================================================================== | 
| 15 |  |  |  |  |  |  | ## Globals | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | ##====================================================================== | 
| 18 |  |  |  |  |  |  | ## Constructors, etc. | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | ## $fmt = $CLASS_OR_OBJ->new(%args) | 
| 21 |  |  |  |  |  |  | ##  + %args: | 
| 22 |  |  |  |  |  |  | sub new { | 
| 23 | 0 |  |  | 0 | 1 |  | my $that = shift; | 
| 24 | 0 |  | 0 |  |  |  | return bless { @_ }, ref($that)||$that; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | ## $fmt = $fmt->reset() | 
| 28 |  |  |  |  |  |  | ##  + reset counters, etc. | 
| 29 | 0 |  |  | 0 | 1 |  | sub reset { return $_[0]; } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | ##====================================================================== | 
| 32 |  |  |  |  |  |  | ## API | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | ## $str = $fmt->toString($hitList) | 
| 35 |  |  |  |  |  |  | sub toString { | 
| 36 | 0 |  |  | 0 | 1 |  | my ($fmt,$hits) = @_; | 
| 37 | 0 |  |  |  |  |  | return "$hits"; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | ## undef = $fmt->toFile($hitList,$file) | 
| 41 |  |  |  |  |  |  | ##  + default implementation calls $fmt->toFh() | 
| 42 |  |  |  |  |  |  | sub toFile { | 
| 43 | 0 |  |  | 0 | 1 |  | my ($fmt,$hits,$file) = @_; | 
| 44 | 0 | 0 |  |  |  |  | my $fh = ref($file) ? $file : IO::File->new(">$file"); | 
| 45 | 0 | 0 |  |  |  |  | confess(ref($fmt)."::toFile(): open failed for '$file': $!") if (!$fh); | 
| 46 | 0 |  |  |  |  |  | my $rc = $fmt->toFh($hits,$fh); | 
| 47 | 0 | 0 |  |  |  |  | $fh->close() if (!ref($file)); | 
| 48 | 0 |  |  |  |  |  | return $rc; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | ## undef = $fmt->toFh($hitList,$fh) | 
| 52 |  |  |  |  |  |  | ##  + default implementation calls $fmt->toString() | 
| 53 |  |  |  |  |  |  | sub toFh { | 
| 54 | 0 |  |  | 0 | 1 |  | my ($fmt,$hits,$fh) = @_; | 
| 55 | 0 |  |  |  |  |  | $fh->print($fmt->toString($hits)); | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 1; ##-- be happy | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | __END__ |