line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::YAML;
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
CGI::Application::Plugin::YAML - YAML methods for CGI::App
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Just a little wrapper. Useful to add YAML methods to you CGI::App object. The
|
11
|
|
|
|
|
|
|
whole YAML module is lazy loaded, so all that gets loaded at first is this
|
12
|
|
|
|
|
|
|
little wrapper.
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use CGI::Application::Plugin::YAML qw( :std );
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Load YAML:-
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$self->YAML->Load( $yamldata );
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Dump YAML:-
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self->YAML->Dump( $perldata );
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
The methods LoadFile and DumpFile can also be imported. You need to specify
|
25
|
|
|
|
|
|
|
:max on your use.
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use CGI::Application::Plugin::YAML qw( :all );
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Load YAML file:-
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->YAML->LoadFile( $yamldata );
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Dump YAML file:-
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->YAML->DumpFile( $perldata );
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module is a wrapper around C.
|
40
|
|
|
|
|
|
|
It uses YAML::Any so looks for the best YAML module your system has to offer.
|
41
|
|
|
|
|
|
|
There are Pure Perl YAML modules (such as YAML::Old) that you can easily
|
42
|
|
|
|
|
|
|
package with your app.
|
43
|
|
|
|
|
|
|
If like me you didn't like the idea of having functions called Dump and Load
|
44
|
|
|
|
|
|
|
imported to your namespace, then I'd use this wapper.
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 Methods
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 YAML
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This is the object that gets exported.
|
51
|
|
|
|
|
|
|
See L
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 Export groups
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Only an object called YAML is exported. The export groups allow you to choose
|
56
|
|
|
|
|
|
|
what methods that object contains.
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
:all exports:-
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Dump Load DumpFile LoadFile
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
:std exports:-
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Dump Load
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 FAQ
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 Why?
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Having C and C as functions are far to ambiguous for my liking.
|
71
|
|
|
|
|
|
|
This also making inheritance on the YAML methods a lot easier.
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 Thanks to:-
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 Come join the bestest Perl group in the World!
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Bristol and Bath Perl moungers is renowned for being the friendliest Perl group
|
80
|
|
|
|
|
|
|
in the world. You don't have to be from the UK to join, everyone is welcome on
|
81
|
|
|
|
|
|
|
the list:-
|
82
|
|
|
|
|
|
|
L
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Lyle Hopkins ;)
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
1
|
|
23718
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
93
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
94
|
1
|
|
|
1
|
|
7
|
use Carp;
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
82
|
|
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
1
|
|
6
|
use vars qw ( $VERSION @ISA @EXPORT_OK %EXPORT_TAGS $IMPORTGROUP );
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
520
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
require Exporter;
|
99
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
@EXPORT_OK = ( 'YAML' );
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
%EXPORT_TAGS = (
|
104
|
|
|
|
|
|
|
all => [ 'YAML' ],
|
105
|
|
|
|
|
|
|
std => [ 'YAML' ],
|
106
|
|
|
|
|
|
|
);
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$VERSION = '0.03';
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#$IMPORTGROUP = ':std';
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $yaml;
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub import {
|
115
|
|
|
|
|
|
|
# local( $IMPORTGROUP );
|
116
|
|
|
|
|
|
|
# $IMPORTGROUP = $_[1];
|
117
|
1
|
|
|
1
|
|
14
|
$yaml = new CGI::Application::Plugin::YAML::guts( $_[1] );
|
118
|
1
|
|
|
|
|
81
|
CGI::Application::Plugin::YAML->export_to_level(1, @_);
|
119
|
|
|
|
|
|
|
}#sub
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub YAML {
|
122
|
0
|
0
|
|
0
|
1
|
0
|
unless ( $yaml->{params}->{__loaded} ) {
|
123
|
0
|
|
|
|
|
0
|
$yaml->__LoadYAML();
|
124
|
|
|
|
|
|
|
}#unless
|
125
|
0
|
|
|
|
|
0
|
return $yaml;
|
126
|
|
|
|
|
|
|
}#sub
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
package CGI::Application::Plugin::YAML::guts;
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub new {
|
132
|
1
|
|
|
1
|
|
2
|
my $class = shift;
|
133
|
|
|
|
|
|
|
# require YAML::Any;
|
134
|
1
|
|
|
|
|
5
|
my $obj = {
|
135
|
|
|
|
|
|
|
params => {
|
136
|
|
|
|
|
|
|
group => shift,
|
137
|
|
|
|
|
|
|
},
|
138
|
|
|
|
|
|
|
};
|
139
|
1
|
50
|
|
|
|
7
|
$obj->{params}->{group} = ':std' unless $obj->{params}->{group};
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# if ( $CGI::Application::Plugin::YAML::IMPORTGROUP eq ':all' ) {
|
142
|
1
|
50
|
|
|
|
5
|
if ( $obj->{params}->{group} eq ':all' ) {
|
143
|
|
|
|
|
|
|
# YAML->import( qw( Dump Load DumpFile LoadFile ) );
|
144
|
|
|
|
|
|
|
### Overloading imported routines as class causes problems when called
|
145
|
|
|
|
|
|
|
sub LoadFile {
|
146
|
0
|
|
|
0
|
|
|
shift; ### get rid of class
|
147
|
0
|
|
|
|
|
|
YAML::Any::LoadFile( @_ );
|
148
|
|
|
|
|
|
|
}#sub
|
149
|
|
|
|
|
|
|
sub DumpFile {
|
150
|
0
|
|
|
0
|
|
|
shift;
|
151
|
0
|
|
|
|
|
|
YAML::Any::DumpFile( @_ );
|
152
|
|
|
|
|
|
|
}#sub
|
153
|
|
|
|
|
|
|
}#if
|
154
|
|
|
|
|
|
|
else {
|
155
|
1
|
|
|
|
|
8
|
YAML->import( qw( Dump Load ) );
|
156
|
|
|
|
|
|
|
}#else
|
157
|
|
|
|
|
|
|
sub Load {
|
158
|
0
|
|
|
0
|
|
|
shift;
|
159
|
0
|
|
|
|
|
|
YAML::Any::Load( @_ );
|
160
|
|
|
|
|
|
|
}#sub
|
161
|
|
|
|
|
|
|
sub Dump {
|
162
|
0
|
|
|
0
|
|
|
shift;
|
163
|
0
|
|
|
|
|
|
YAML::Any::Dump( @_ );
|
164
|
|
|
|
|
|
|
}#sub
|
165
|
1
|
|
|
|
|
3
|
bless( $obj, $class );
|
166
|
1
|
|
|
|
|
3
|
return $obj;
|
167
|
|
|
|
|
|
|
}#sub
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub __LoadYAML {
|
171
|
0
|
|
|
0
|
|
|
require YAML::Any;
|
172
|
0
|
|
|
|
|
|
YAML->import( qw( Dump Load DumpFile LoadFile ) );
|
173
|
|
|
|
|
|
|
}#sub
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1;
|