4 # Author: Andreas Marienborg <andreas.marienborg@gmail.com>
5 # Donated as is to xapian project. Use and modify as see fit
8 my $dir = shift || '.';
9 if ($dir eq '--help') {
10 print "Syntax: $0 [<path to srcdir> [<xapian version>]\n\n";
11 print "This script needs to know the source directory to find\n";
12 print "exception_data.pm - by default it looks in '.'.\n";
17 $::version
= shift || '';
18 if ($::version
=~ /^(\d+)\.(\d+)\,(\d+)/) {
19 $::version
= $1 * 1000000 + $2 * 1000 + $3;
21 # Assume 1.4.x if not specified.
26 # We load the exception data from xapian-core.
27 use exception_data
qw(@baseclasses @classes %subclasses);
29 # Generate typemaps for Xapian::Error and its subclasses.
30 my $tm = "typemap-errorclasses";
31 open(TM, ">", "$tm.tmp")
32 or die "cannot write '$tm.tmp': $!\n";
34 foreach (@baseclasses, @classes) {
35 my ($classname, $parent, $desc) = split /\t/;
36 print TM "$classname\tO_OBJECT\n";
37 print TM "$classname *\tO_OBJECT\n";
42 or die "Failed to rename '$tm.tmp' to '$tm': $!\n";
44 my $fnm = "Xapian/Error.pm";
45 open F, '>', "$fnm.tmp" or die $!;
48 package Search::Xapian::Error;
52 Search::Xapian::Error - Base class for all exceptions in Search::Xapian
56 This is an abstract class in C++, i.e. it cannot be instantiated directly.
57 In Perl there is no such concept, but you should not need to create instances
58 of this class yourself.
62 All exception objects have the following methods
66 Returns a string with a descriptive error message, useful for outputting
70 The type of this error (e.g. "DocNotFoundError").
74 Optional context information, returned as a string
76 =head2 get_error_string
78 Returns any error string from errno or similar associated with this error
90 foreach my $subclass (@
{$subclasses{'Error'}}) {
91 print F
"use Search::Xapian::$subclass;\n";
96 our @ISA = qw(DynaLoader);
98 # Preloaded methods go here.
100 # In a new thread, copy objects of this class to unblessed, undef values.
115 rename "$fnm.tmp", "$fnm" or die $!;
117 foreach ('Error', @baseclasses, @classes) {
118 my ($classname, $parent, $full_description) = split /\t/;
121 $fnm = "XS/$classname.xs";
122 open F
, '>', "$fnm.tmp" or die $!;
125 MODULE = Search::Xapian\t PACKAGE = Search::Xapian::$classname
130 ${classname}::get_type()
133 ${classname}::get_msg()
136 ${classname}::get_context()
139 ${classname}::get_error_string()
142 ${classname}::DESTROY()
145 if (exists $subclasses{$classname}) {
147 foreach my $subclass (@
{$subclasses{$classname}}) {
148 print F
"INCLUDE: XS/$subclass.xs\n";
153 rename "$fnm.tmp", "$fnm" or die $!;
155 next if $classname eq 'Error';
157 $full_description =~ s!^[/ ]\*[*/]?!!mg;
158 $full_description =~ s!\*\/$!!mg; # ! to unconfuse vim
160 my ($heading, $desc) = split('\n\n', $full_description, 2);
163 # Xapian/CLASSNAME.pm
164 $fnm = "Xapian/$classname.pm";
165 open F
, '>', "$fnm.tmp" or die $!;
168 package Search::Xapian::$classname;
172 Search::Xapian::$classname - $heading
185 # For compatibility with XS Search::Xapian < 1.2.3 which still threw strings
187 use overload '""' => sub { "Exception: ".\$_[0]->get_msg };
191 if (exists $subclasses{$classname}) {
192 foreach my $subclass (@
{$subclasses{$classname}}) {
193 print F
"use Search::Xapian::$subclass;\n";
199 our \@ISA = qw(DynaLoader Search::Xapian::$parent);
205 rename "$fnm.tmp", "$fnm" or die $!;
208 # write new handle_exception.cc
210 $fnm = "handle_exception.cc";
211 open F
, '>', "$fnm.tmp" or die $!;
222 /* handle_exception function
224 * called in catch blocks to croak or rethrow in perl land
227 void handle_exception(void) {
232 foreach (reverse @classes) {
233 my ($classname, $parent, $full_description) = split /\t/;
236 } catch (const Xapian::$classname & error) {
237 SV * errsv = get_sv("\@", TRUE);
238 sv_setref_pv(errsv, "Search::Xapian::$classname", (void *) new Xapian::$classname(error));
244 } catch (const std::exception & error) {
245 croak( "std::exception: %s", error.what());
247 croak("something terrible happened");
253 rename "$fnm.tmp", "$fnm" or die $!;