| 1 | ##-*- Mode: CPerl -*- | ||
| 2 | |||
| 3 | ## File: DDC::Format::YAML.pm | ||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||
| 5 | ## Description: | ||
| 6 | ## + DDC Query utilities: output formatting: YAML | ||
| 7 | ##====================================================================== | ||
| 8 | |||
| 9 | package DDC::Format::YAML; | ||
| 10 | use YAML::XS; | ||
| 11 | use Carp; | ||
| 12 | use strict; | ||
| 13 | |||
| 14 | ##====================================================================== | ||
| 15 | ## Globals | ||
| 16 | our @ISA = qw(DDC::Format); | ||
| 17 | |||
| 18 | ##====================================================================== | ||
| 19 | ## Constructors, etc. | ||
| 20 | |||
| 21 | ## $fmt = $CLASS_OR_OBJ->new(%args) | ||
| 22 | ## + %args: | ||
| 23 | ## ( | ||
| 24 | ## level => $level, ##-- yaml prettification level (default:0) | ||
| 25 | ## ) | ||
| 26 | sub new { | ||
| 27 | my $that = shift; | ||
| 28 | my $fmt = bless { | ||
| 29 | level=>0, | ||
| 30 | @_ | ||
| 31 | }, ref($that)||$that; | ||
| 32 | return $fmt; | ||
| 33 | } | ||
| 34 | |||
| 35 | ## $fmt = $fmt->reset() | ||
| 36 | ## + reset counters, etc. | ||
| 37 | #sub reset { | ||
| 38 | # return $_[0]->SUPER::reset(); | ||
| 39 | #} | ||
| 40 | |||
| 41 | ##====================================================================== | ||
| 42 | ## Helper functions | ||
| 43 | |||
| 44 | ## $hitStr = $fmt->hitString($hit) | ||
| 45 | sub hitString { | ||
| 46 | #my ($fmt,$hit) = @_; | ||
| 47 | return YAML::XS::Dump($_[1]); | ||
| 48 | } | ||
| 49 | |||
| 50 | ##====================================================================== | ||
| 51 | ## API | ||
| 52 | |||
| 53 | ## $str = $fmt->toString(\@hits) | ||
| 54 | sub toString { | ||
| 55 | my ($fmt,$hits) = @_; | ||
| 56 | return YAML::XS::Dump($_[1]); | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; ##-- be happy | ||
| 60 | |||
| 61 | __END__ |