| 1 | #======================================================================== | ||
| 2 | # | ||
| 3 | # Badger::Codec::YAML | ||
| 4 | # | ||
| 5 | # DESCRIPTION | ||
| 6 | # Codec module for encoding/decoding YAML | ||
| 7 | # | ||
| 8 | # AUTHOR | ||
| 9 | # Andy Wardley <abw@wardley.org> | ||
| 10 | # | ||
| 11 | #======================================================================== | ||
| 12 | |||
| 13 | package Badger::Codec::YAML; | ||
| 14 | |||
| 15 | use Badger::Class | ||
| 16 | 3 | version => 0.01, | |
| 17 | base => 'Badger::Codec', | ||
| 18 | 3 | ▶ | import => 'class CLASS'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | eval "require YAML::XS"; | ||
| 21 | our $HAS_YAML_XS = $@ ? 0 : 1; | ||
| 22 | our $HAS_YAML; | ||
| 23 | |||
| 24 | unless ($HAS_YAML_XS) { | ||
| 25 | eval "require YAML"; | ||
| 26 | $HAS_YAML = $@ ? 0 : 1; | ||
| 27 | } | ||
| 28 | |||
| 29 | our $MODULE = | ||
| 30 | $HAS_YAML_XS ? 'YAML::XS' : | ||
| 31 | $HAS_YAML ? 'YAML' : | ||
| 32 | CLASS->error("You don't have YAML or YAML::XS installed"); | ||
| 33 | #die "No YAML implementation installed\n"; | ||
| 34 | |||
| 35 | *yaml_dump = $HAS_YAML_XS ? \&YAML::XS::Dump : \&YAML::Dump; | ||
| 36 | *yaml_load = $HAS_YAML_XS ? \&YAML::XS::Load : \&YAML::Load; | ||
| 37 | |||
| 38 | sub encode { | ||
| 39 | 0 | ▶ | my $self = shift; |
|
Subroutine
encode: not called CC=1 SCAR=6.9
| |||
| 40 | 0 | yaml_dump(shift); | |
| 41 | } | ||
| 42 | |||
| 43 | sub decode { | ||
| 44 | 0 | ▶ | my $self = shift; |
|
Subroutine
decode: not called CC=1 SCAR=6.9
| |||
| 45 | 0 | yaml_load(shift); | |
| 46 | } | ||
| 47 | |||
| 48 | # shortcuts straight to the real encoder/decoder subs for efficient aliasing | ||
| 49 | |||
| 50 | sub encoder { | ||
| 51 | 0 | ▶ | \&yaml_dump; |
|
Subroutine
encoder: not called CC=1 SCAR=6.9
| |||
| 52 | } | ||
| 53 | |||
| 54 | sub decoder { | ||
| 55 | 0 | ▶ | \&yaml_load; |
|
Subroutine
decoder: not called CC=1 SCAR=6.9
| |||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | 1; | ||
| 60 | |||
| 61 | |||
| 62 | __END__ | ||