Debian Codegraph @

perl/lib/RDF/Redland.pm.in

raw
1 # -*- Mode: Perl -*-
2 #
3 # Redland.pm - Redland top level Perl module
4 #
5 # Copyright (C) 2000-2005 David Beckett - http://www.dajobe.org/
6 # Copyright (C) 2000-2005 University of Bristol - http://www.bristol.ac.uk/
7 #
8 # This package is Free Software and part of Redland http://librdf.org/
9 #
10 # It is licensed under the following three licenses as alternatives:
11 # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 # 2. GNU General Public License (GPL) V2 or any newer version
13 # 3. Apache License, V2.0 or any newer version
14 #
15 # You may not use this file except in compliance with at least one of
16 # the above three licenses.
17 #
18 # See LICENSE.html or LICENSE.txt at the top of this package for the
19 # full license terms.
20 #
21 #
22 #
23
24 use RDF::Redland::Iterator;
25 use RDF::Redland::Model;
26 use RDF::Redland::Node;
27 use RDF::Redland::BlankNode;
28 use RDF::Redland::URINode;
29 use RDF::Redland::LiteralNode;
30 use RDF::Redland::XMLLiteralNode;
31 use RDF::Redland::Parser;
32 use RDF::Redland::Query;
33 use RDF::Redland::QueryResults;
34 use RDF::Redland::Serializer;
35 use RDF::Redland::Statement;
36 use RDF::Redland::Storage;
37 use RDF::Redland::Stream;
38 use RDF::Redland::URI;
39
40 use RDF::Redland::CORE;
41
42 package RDF::Redland::World;
43
44 sub new ($) {
45 my($proto)=@_;
46 my $class = ref($proto) || $proto;
47 my $self = {};
48
49 # This line is needed because otherwise will perl will barf a
50 # warning (that CANNOT be disabled with no warnings 'once') about
51 # an unused variable.
52 $_p_librdf_world_s::OWNER = 1;
53
54 $self->{WORLD} = &RDF::Redland::CORE::librdf_new_world();
55 &RDF::Redland::CORE::librdf_world_open($self->{WORLD});
56
57 &RDF::Redland::CORE::librdf_perl_world_init($self->{WORLD});
58
59 bless ($self, $class);
60 $self->{ME}=$self;
61 return $self;
62 }
63
64 sub DESTROY ($) {
65 warn "RDF::World DESTROY\n" if $RDF::Debug;
66 &RDF::Redland::CORE::librdf_perl_world_finish();
67 }
68
69 sub message ($$$$$$$$$) {
70 if(ref $RDF::Redland::Log_Sub) {
71 return $RDF::Redland::Log_Sub->(@_);
72 }
73
74 my($code, $level, $facility, $message, $line, $column, $byte, $file, $uri)=@_;
75 if($level > 3) {
76 if(ref $RDF::Redland::Error_Sub) {
77 return $RDF::Redland::Error_Sub->($message);
78 } else {
79 die "Redland error: $message\n";
80 }
81 } else {
82 if(ref $RDF::Redland::Warning_Sub) {
83 return $RDF::Redland::Warning_Sub->($message);
84 } else {
85 warn "Redland warning: $message\n";
86 }
87 }
88 1;
89 }
90
91 package RDF::Redland;
92
93 use vars qw($VERSION $Debug $World $Error_Sub $Warning_Sub);
94
95 $VERSION= eval sprintf("%s.%02d_%02d_%02d", split(/\./, "@PACKAGE_VERSION@"));
96
97 $Debug=0;
98
99 $World=new RDF::Redland::World;
100
101 $Error_Sub=undef;
102
103 $Warning_Sub=undef;
104
105 $Log_Sub=undef;
106
107 =pod
108
109 =head1 NAME
110
111 RDF::Redland - Redland RDF Class
112
113 =head1 SYNOPSIS
114
115 use RDF::Redland;
116 my $storage=new RDF::Redland::Storage("hashes", "test", "new='yes',hash-type='memory'");
117 my $model=new RDF::Redland::Model($storage, "");
118
119 ...
120
121 =head1 DESCRIPTION
122
123 This class initialises the Redland RDF classes.
124
125 See the main classes for full detail:
126 L<RDF::Redland::Node>,
127 L<RDF::Redland::BlankNode>, L<RDF::Redland::URINode>,
128 L<RDF::Redland::LiteralNode>, L<RDF::Redland::XMLLiteralNode>,
129 L<RDF::Redland::URI>,
130 L<RDF::Redland::Statement>, L<RDF::Redland::Model>,
131 L<RDF::Redland::Storage>, L<RDF::Redland::Parser>,
132 L<RDF::Redland::Query>, L<RDF::Redland::QueryResults>,
133 L<RDF::Redland::Iterator>, L<RDF::Redland::Stream>
134 and L<RDF::Redland::RSS>.
135
136 =head1 STATIC METHODS
137
138 =over
139
140 =item set_log_handler SUB
141
142 Set I<SUB> as the subroutine to be called on any Redland error, warning
143 or log message. The subroutine must have the followign signature:
144
145
146 sub handler ($$$$$$$$$) {
147 my($code, $level, $facility, $message, $line, $column, $byte, $file, $uri)=@_;
148 # int error code
149 # int log level
150 # int facility causing the error (parsing, serializing, ...)
151 # string error message
152 # int line number (<0 if not relevant)
153 # int column number (<0 if not relevant)
154 # int byte number (<0 if not relevant)
155 # string file name or undef
156 # string URI or undef
157
158 # ...do something with the information ...
159 };
160
161 RDF::Redland::set_log_handler(\&handler);
162
163 =cut
164
165 sub set_log_handler ($) {
166 $Log_Sub=shift;
167 }
168
169
170 =item reset_log_handler
171
172 Reset redland to use the default logging handler, typically printing
173 the message to stdout or stderr and exiting on a fatal error.
174
175 =cut
176
177 sub reset_log_handler () {
178 $Log_Sub=undef;
179 }
180
181
182 =item set_error_handler SUB
183
184 The method set_log_handler is much more flexible than this and includes
185 this functionality.
186
187 Set I<SUB> as the subroutine to be called on a Redland error with
188 the error message as the single argument. For example:
189
190 RDF::Redland::set_error_handler(sub {
191 my $msg=shift;
192 # Do something with $msg
193 });
194
195 The default if this is not set, is to run die $msg
196
197 =cut
198
199 sub set_error_handler ($) {
200 $Error_Sub=shift;
201 }
202
203
204 =item set_warning_handler SUB
205
206 The method set_log_handler is much more flexible than this and includes
207 this functionality.
208
209 Set I<SUB> as the subroutine to be called on a Redland warning with
210 the warning message as the single argument. For example:
211
212 RDF::Redland::set_warning_handler(sub {
213 my $msg=shift;
214 # Do something with $msg
215 });
216
217 The default if this is not set, is to run warn $msg
218
219 =cut
220
221 sub set_warning_handler ($) {
222 $Warning_Sub=shift;
223 }
224
225 =pod
226
227 =back
228
229 =head1 SEE ALSO
230
231 L<RDF::Redland::Node>,
232 L<RDF::Redland::BlankNode>, L<RDF::Redland::URINode>,
233 L<RDF::Redland::LiteralNode>, L<RDF::Redland::XMLLiteralNode>,
234 L<RDF::Redland::URI>,
235 L<RDF::Redland::Statement>, L<RDF::Redland::Model>,
236 L<RDF::Redland::Storage>, L<RDF::Redland::Parser>,
237 L<RDF::Redland::Query>, L<RDF::Redland::QueryResults>,
238 L<RDF::Redland::Iterator>, L<RDF::Redland::Stream>
239 and L<RDF::Redland::RSS>.
240
241 =head1 AUTHOR
242
243 Dave Beckett - http://www.dajobe.org/
244
245 =cut
246
247 1;