23b9c5ca51f06fa3a5227b05e5c7ed03be32dcca
[kivitendo-erp.git] / modules / override / YAML / Error.pm
1 package YAML::Error;
2 use strict; use warnings;
3 use YAML::Base; use base 'YAML::Base';
4
5 field 'code';
6 field 'type' => 'Error';
7 field 'line';
8 field 'document';
9 field 'arguments' => [];
10
11 my ($error_messages, %line_adjust);
12
13 sub format_message {
14     my $self = shift;
15     my $output = 'YAML ' . $self->type . ': ';
16     my $code = $self->code;
17     if ($error_messages->{$code}) {
18         $code = sprintf($error_messages->{$code}, @{$self->arguments});
19     }
20     $output .= $code . "\n";
21
22     $output .= '   Code: ' . $self->code . "\n"
23         if defined $self->code;
24     $output .= '   Line: ' . $self->line . "\n"
25         if defined $self->line;
26     $output .= '   Document: ' . $self->document . "\n"
27         if defined $self->document;
28     return $output;
29 }
30
31 sub error_messages {
32     $error_messages;
33 }
34
35 %$error_messages = map {s/^\s+//;$_} split "\n", <<'...';
36 YAML_PARSE_ERR_BAD_CHARS
37   Invalid characters in stream. This parser only supports printable ASCII
38 YAML_PARSE_ERR_NO_FINAL_NEWLINE
39   Stream does not end with newline character
40 YAML_PARSE_ERR_BAD_MAJOR_VERSION
41   Can't parse a %s document with a 1.0 parser
42 YAML_PARSE_WARN_BAD_MINOR_VERSION
43   Parsing a %s document with a 1.0 parser
44 YAML_PARSE_WARN_MULTIPLE_DIRECTIVES
45   '%s directive used more than once'
46 YAML_PARSE_ERR_TEXT_AFTER_INDICATOR
47   No text allowed after indicator
48 YAML_PARSE_ERR_NO_ANCHOR
49   No anchor for alias '*%s'
50 YAML_PARSE_ERR_NO_SEPARATOR
51   Expected separator '---'
52 YAML_PARSE_ERR_SINGLE_LINE
53   Couldn't parse single line value
54 YAML_PARSE_ERR_BAD_ANCHOR
55   Invalid anchor
56 YAML_DUMP_ERR_INVALID_INDENT
57   Invalid Indent width specified: '%s'
58 YAML_LOAD_USAGE
59   usage: YAML::Load($yaml_stream_scalar)
60 YAML_PARSE_ERR_BAD_NODE
61   Can't parse node
62 YAML_PARSE_ERR_BAD_EXPLICIT
63   Unsupported explicit transfer: '%s'
64 YAML_DUMP_USAGE_DUMPCODE
65   Invalid value for DumpCode: '%s'
66 YAML_LOAD_ERR_FILE_INPUT
67   Couldn't open %s for input:\n%s
68 YAML_DUMP_ERR_FILE_CONCATENATE
69   Can't concatenate to YAML file %s
70 YAML_DUMP_ERR_FILE_OUTPUT
71   Couldn't open %s for output:\n%s
72 YAML_DUMP_ERR_NO_HEADER
73   With UseHeader=0, the node must be a plain hash or array
74 YAML_DUMP_WARN_BAD_NODE_TYPE
75   Can't perform serialization for node type: '%s'
76 YAML_EMIT_WARN_KEYS
77   Encountered a problem with 'keys':\n%s
78 YAML_DUMP_WARN_DEPARSE_FAILED
79   Deparse failed for CODE reference
80 YAML_DUMP_WARN_CODE_DUMMY
81   Emitting dummy subroutine for CODE reference
82 YAML_PARSE_ERR_MANY_EXPLICIT
83   More than one explicit transfer
84 YAML_PARSE_ERR_MANY_IMPLICIT
85   More than one implicit request
86 YAML_PARSE_ERR_MANY_ANCHOR
87   More than one anchor
88 YAML_PARSE_ERR_ANCHOR_ALIAS
89   Can't define both an anchor and an alias
90 YAML_PARSE_ERR_BAD_ALIAS
91   Invalid alias
92 YAML_PARSE_ERR_MANY_ALIAS
93   More than one alias
94 YAML_LOAD_ERR_NO_CONVERT
95   Can't convert implicit '%s' node to explicit '%s' node
96 YAML_LOAD_ERR_NO_DEFAULT_VALUE
97   No default value for '%s' explicit transfer
98 YAML_LOAD_ERR_NON_EMPTY_STRING
99   Only the empty string can be converted to a '%s'
100 YAML_LOAD_ERR_BAD_MAP_TO_SEQ
101   Can't transfer map as sequence. Non numeric key '%s' encountered.
102 YAML_DUMP_ERR_BAD_GLOB
103   '%s' is an invalid value for Perl glob
104 YAML_DUMP_ERR_BAD_REGEXP
105   '%s' is an invalid value for Perl Regexp
106 YAML_LOAD_ERR_BAD_MAP_ELEMENT
107   Invalid element in map
108 YAML_LOAD_WARN_DUPLICATE_KEY
109   Duplicate map key found. Ignoring.
110 YAML_LOAD_ERR_BAD_SEQ_ELEMENT
111   Invalid element in sequence
112 YAML_PARSE_ERR_INLINE_MAP
113   Can't parse inline map
114 YAML_PARSE_ERR_INLINE_SEQUENCE
115   Can't parse inline sequence
116 YAML_PARSE_ERR_BAD_DOUBLE
117   Can't parse double quoted string
118 YAML_PARSE_ERR_BAD_SINGLE
119   Can't parse single quoted string
120 YAML_PARSE_ERR_BAD_INLINE_IMPLICIT
121   Can't parse inline implicit value '%s'
122 YAML_PARSE_ERR_BAD_IMPLICIT
123   Unrecognized implicit value '%s'
124 YAML_PARSE_ERR_INDENTATION
125   Error. Invalid indentation level
126 YAML_PARSE_ERR_INCONSISTENT_INDENTATION
127   Inconsistent indentation level
128 YAML_LOAD_WARN_UNRESOLVED_ALIAS
129   Can't resolve alias *%s
130 YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP
131   No 'REGEXP' element for Perl regexp
132 YAML_LOAD_WARN_BAD_REGEXP_ELEM
133   Unknown element '%s' in Perl regexp
134 YAML_LOAD_WARN_GLOB_NAME
135   No 'NAME' element for Perl glob
136 YAML_LOAD_WARN_PARSE_CODE
137   Couldn't parse Perl code scalar: %s
138 YAML_LOAD_WARN_CODE_DEPARSE
139   Won't parse Perl code unless $YAML::LoadCode is set
140 YAML_EMIT_ERR_BAD_LEVEL
141   Internal Error: Bad level detected
142 YAML_PARSE_WARN_AMBIGUOUS_TAB
143   Amibiguous tab converted to spaces
144 YAML_LOAD_WARN_BAD_GLOB_ELEM
145   Unknown element '%s' in Perl glob
146 YAML_PARSE_ERR_ZERO_INDENT
147   Can't use zero as an indentation width
148 YAML_LOAD_WARN_GLOB_IO
149   Can't load an IO filehandle. Yet!!!
150 ...
151
152 %line_adjust = map {($_, 1)} 
153   qw(YAML_PARSE_ERR_BAD_MAJOR_VERSION
154      YAML_PARSE_WARN_BAD_MINOR_VERSION 
155      YAML_PARSE_ERR_TEXT_AFTER_INDICATOR 
156      YAML_PARSE_ERR_NO_ANCHOR 
157      YAML_PARSE_ERR_MANY_EXPLICIT
158      YAML_PARSE_ERR_MANY_IMPLICIT
159      YAML_PARSE_ERR_MANY_ANCHOR
160      YAML_PARSE_ERR_ANCHOR_ALIAS
161      YAML_PARSE_ERR_BAD_ALIAS
162      YAML_PARSE_ERR_MANY_ALIAS
163      YAML_LOAD_ERR_NO_CONVERT
164      YAML_LOAD_ERR_NO_DEFAULT_VALUE
165      YAML_LOAD_ERR_NON_EMPTY_STRING
166      YAML_LOAD_ERR_BAD_MAP_TO_SEQ
167      YAML_LOAD_ERR_BAD_STR_TO_INT
168      YAML_LOAD_ERR_BAD_STR_TO_DATE
169      YAML_LOAD_ERR_BAD_STR_TO_TIME
170      YAML_LOAD_WARN_DUPLICATE_KEY
171      YAML_PARSE_ERR_INLINE_MAP
172      YAML_PARSE_ERR_INLINE_SEQUENCE
173      YAML_PARSE_ERR_BAD_DOUBLE
174      YAML_PARSE_ERR_BAD_SINGLE
175      YAML_PARSE_ERR_BAD_INLINE_IMPLICIT
176      YAML_PARSE_ERR_BAD_IMPLICIT
177      YAML_LOAD_WARN_NO_REGEXP_IN_REGEXP
178      YAML_LOAD_WARN_BAD_REGEXP_ELEM
179      YAML_LOAD_WARN_REGEXP_CREATE
180      YAML_LOAD_WARN_GLOB_NAME
181      YAML_LOAD_WARN_PARSE_CODE
182      YAML_LOAD_WARN_CODE_DEPARSE
183      YAML_LOAD_WARN_BAD_GLOB_ELEM
184      YAML_PARSE_ERR_ZERO_INDENT
185     );
186
187 package YAML::Warning;
188 use base 'YAML::Error';
189
190 1;
191
192 __END__
193
194 =head1 NAME
195
196 YAML::Error - Error formatting class for YAML modules
197
198 =head1 SYNOPSIS
199
200     $self->die('YAML_PARSE_ERR_NO_ANCHOR', $alias);
201     $self->warn('YAML_LOAD_WARN_DUPLICATE_KEY');
202
203 =head1 DESCRIPTION
204
205 This module provides a C<die> and a C<warn> facility.
206
207 =head1 AUTHOR
208
209 Ingy döt Net <ingy@cpan.org>
210
211 =head1 COPYRIGHT
212
213 Copyright (c) 2006. Ingy döt Net. All rights reserved.
214
215 This program is free software; you can redistribute it and/or modify it
216 under the same terms as Perl itself.
217
218 See L<http://www.perl.com/perl/misc/Artistic.html>
219
220 =cut