| 1 | # | ||||||||||
| 2 | # $Id: YAML.pm,v 0.05 2020/08/05 18:26:03 dankogai Exp dankogai $ | ||||||||||
| 3 | # | ||||||||||
| 4 | package Tie::YAML; | ||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | our $VERSION = sprintf "%d.%02d", q$Revision: 0.05 $ =~ /(\d+)/g; | |||||||||
| 8 | 1 | ▶ | use base 'Tie::SaveLater'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use YAML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | __PACKAGE__->make_subclasses; | |||||||||
| 12 | |||||||||||
| 13 | 5 | ▶ | sub load{ | ||||||||
|
Subroutine
load: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 14 | # See https://rt.cpan.org/Public/Bug/Display.html?id=131985 | ||||||||||
| 15 | 5 | local $YAML::LoadBlessed = 1; | |||||||||
| 16 | 5 | my $class = shift; | |||||||||
| 17 | 5 | my $filename = shift; | |||||||||
| 18 | 5 | ▶ | open my $fh, "<:raw", $filename or croak "$filename: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 5 | local $/; # slurp; | |||||||||
| 20 | 5 | my $yaml = <$fh>; | |||||||||
| 21 | 5 | close $fh; | |||||||||
| 22 | 5 | return Load($yaml); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 8 | ▶ | sub save{ | ||||||||
|
Subroutine
save: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 26 | 8 | my $self = shift; | |||||||||
| 27 | 8 | my $filename = $self->filename; | |||||||||
| 28 | 8 | ▶ | open my $fh, ">:raw", $filename or croak "$filename: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 8 | print $fh Dump(damn_scalar($self)); | |||||||||
| 30 | 8 | close $fh; | |||||||||
| 31 | 8 | return 1; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 8 | ▶ | sub damn_scalar { # iff necessary | ||||||||
|
Subroutine
damn_scalar: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | 8 | ▶ | return $_[0] unless ref($_[0]) =~ /::SCALAR$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 4 | return \do{ my $scalar = ${ $_[0] }} | |||||||||
| 37 | } | ||||||||||
| 38 | 1 | 1; | |||||||||
| 39 | __END__ | ||||||||||