blib/lib/OSPF/LSDB/YAML.pm

filter: Statementstmt 100% 28 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 100% 40 / 40 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« script/gated2yaml ↑ Summary
1 ##########################################################################
2 # Copyright (c) 2010-2021 Alexander Bluhm <alexander.bluhm@gmx.net>
3 #
4 # Permission to use, copy, modify, and distribute this software for any
5 # purpose with or without fee is hereby granted, provided that the above
6 # copyright notice and this permission notice appear in all copies.
7 #
8 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 ##########################################################################
16  
17 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 =pod
21  
22 =head1 NAME
23  
24 OSPF::LSDB::YAML - load or dump OSPF link state database as YAML
25  
26 =head1 SYNOPSIS
27  
28 use OSPF::LSDB;
29  
30 use OSPF::LSDB::YAML;
31  
32 my $ospf = OSPF::LSDB-E<gt>new();
33  
34 my $yaml = OSPF::LSDB::YAML-E<gt>new($ospf);
35  
36 $string = $yaml-E<gt>Dump();
37  
38 $yaml-E<gt>DumpFile($filename);
39  
40 $yaml-E<gt>Load($string);
41  
42 $yaml-E<gt>LoadFile($filename);
43  
44 =head1 DESCRIPTION
45  
46 The OSPF::LSDB::YAML module allows to load or dump a L<OSPF::LSDB>
47 instance in YAML format.
48  
49 =cut
50  
51 package OSPF::LSDB::YAML;
52 28 ▶use base qw(OSPF::LSDB);
Subroutine BEGIN: called CC=1 SCAR=0.0
53 28 ▶use YAML::Syck qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 =pod
56  
57 =over 4
58  
59 =item $self-E<gt>Dump()
60  
61 Return the L<OSPF::LSDB> content as YAML string.
62  
63 =cut
64  
65 sub Dump {
66 6 ▶ my OSPF::LSDB $self = shift;
Subroutine Dump: called CC=1 SCAR=0.0
Pod documented
67 6 return YAML::Syck::Dump($self->{ospf});
68 }
69  
70 =pod
71  
72 =item $self-E<gt>DumpFile($filepath)
73  
74 Write the L<OSPF::LSDB> content as YAML into a file.
75  
76 =cut
77  
78 sub DumpFile {
79 6 ▶ my OSPF::LSDB $self = shift;
Subroutine DumpFile: called CC=1 SCAR=0.0
Pod documented
80 6 my $filepath = shift;
81 6 YAML::Syck::DumpFile($filepath, $self->{ospf});
82 }
83  
84 =pod
85  
86 =item $self-E<gt>Load($string)
87  
88 Set the L<OSPF::LSDB> base object to the given YAML string.
89 The content is converted to the current version and is validated.
90  
91 =cut
92  
93 sub Load {
94 170 ▶ my OSPF::LSDB $self = shift;
Subroutine Load: called CC=1 SCAR=0.0
Pod documented
95 170 my $string = shift;
96 170 $self->{ospf} = YAML::Syck::Load($string);
97 170 $self->convert();
98 170 $self->validate();
99 }
100  
101 =pod
102  
103 =item $self-E<gt>LoadFile($filepath)
104  
105 Set the L<OSPF::LSDB> base object to the given YAML file.
106 The content is converted to the current version and is validated.
107  
108 =back
109  
110 =cut
111  
112 sub LoadFile {
113 15 ▶ my OSPF::LSDB $self = shift;
Subroutine LoadFile: called CC=1 SCAR=0.0
Pod documented
114 15 my $filepath = shift;
115 15 $self->{ospf} = YAML::Syck::LoadFile($filepath);
116 15 $self->convert();
117 15 $self->validate();
118 }
119  
120 =pod
121  
122 =head1 ERRORS
123  
124 The methods die if any error occures.
125  
126 =head1 SEE ALSO
127  
128 L<OSPF::LSDB>,
129  
130 L<ospfconvert>
131  
132 =head1 AUTHORS
133  
134 Alexander Bluhm
135  
136 =cut
137  
138 28 1;
« script/gated2yaml ↑ Summary