line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Yukki::Role::Savable; |
2
|
|
|
|
|
|
|
$Yukki::Role::Savable::VERSION = '0.991_002'; # TRIAL |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
28262
|
$Yukki::Role::Savable::VERSION = '0.991002';use v5.24; |
|
3
|
|
|
|
|
22
|
|
5
|
3
|
|
|
3
|
|
27
|
use utf8; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
35
|
|
6
|
3
|
|
|
3
|
|
99
|
use Moo::Role; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
29
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1222
|
use Scalar::Util qw( blessed ); |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
240
|
|
9
|
3
|
|
|
3
|
|
723
|
use YAML qw( Dump Load ); |
|
3
|
|
|
|
|
11030
|
|
|
3
|
|
|
|
|
607
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Provides a mechanism for YAML-izing objects |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
requires 'savable_attributes'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub dump_yaml { |
18
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my %output; |
21
|
0
|
|
|
|
|
|
for my $attr ($self->savable_attributes) { |
22
|
0
|
|
|
|
|
|
my $v = $self->$attr; |
23
|
0
|
0
|
0
|
|
|
|
if (blessed $v && $v->does('Yukki::Role::Savable')) { |
24
|
0
|
|
|
|
|
|
$v = $v->dump_yaml; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
$output{ $attr } = $v; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return Dump(\%output); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub load_yaml { |
34
|
0
|
|
|
0
|
1
|
|
my ($class, $yaml) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $input = Load($yaml); |
37
|
0
|
|
|
|
|
|
$class->new($input); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding UTF-8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Yukki::Role::Savable - Provides a mechanism for YAML-izing objects |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 VERSION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
version 0.991_002 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package Yukki::Things; |
59
|
|
|
|
|
|
|
use v5.24; |
60
|
|
|
|
|
|
|
use Moo; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
with 'Yukki::Role::Savable'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has foo => ( is => 'ro' ); |
65
|
|
|
|
|
|
|
has bar => ( is => 'ro' ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub savable_attributes { qw( foo bar ) } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $things = Yukki::Things->new(foo => 1, bar => 2); |
70
|
|
|
|
|
|
|
path('file.yaml')->spew_utf8($things->dump_yaml); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $things = Yukki::Things->load_yaml(path('file.yaml')->slurp_utf8); |
73
|
|
|
|
|
|
|
say $things->foo; #> 1 |
74
|
|
|
|
|
|
|
say $things->bar; #> 2 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This is intended to provide L<Yukki> with a nice, neat way to save and load some configuration objects in a standard way. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 savable_attributes |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my @attr = $obj->savable_attributes; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns the list of attributes to save in the YAML. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 METHODS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 dump_yaml |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $yaml_text = $obj->dump_yaml; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This converts the object to YAML and returns the ext. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 load_yaml |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $obj = $class->load_yaml($yaml_text); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This constructs a new class from the data loaded from the given YAML text. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Qubling Software LLC. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
111
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |