root/lang/perl/Senna/trunk/lib/Senna/RC.pm @ 3917

Revision 3917, 1.1 kB (checked in by daisuke, 5 years ago)

Add tests for rc

  • Property svn:keywords set to Id
Line 
1# $Id$
2#
3# Copyright (c) 2005-2007 Daisuke Maki <dmaki@cpan.org>
4# All rights reserved.
5
6package Senna::RC;
7use strict;
8use Senna::Constants;
9use overload
10    '""'       => \&value,
11    '0+'       => \&value,
12    'bool'     => \&_to_bool,
13    'fallback' => 1
14;
15
16sub new
17{
18    my $class = shift;
19    my $value = shift;
20    return bless \$value, $class;
21}
22
23sub value   { ${$_[0]} }
24sub _to_bool { ${$_[0]} == &Senna::Constants::SEN_RC_SUCCESS }
25
261;
27
28__END__
29
30=head1 NAME
31
32Senna::RC - Wrapper for sen_rc
33
34=head1 SYNOPSIS
35
36  use Senna::RC;
37  use Senna::Constants qw(SEN_SUCCESS);
38
39  my $rc = Senna::RC->new(SEN_SUCCESS);
40  if ($rc) {
41     print "success!\n";
42  }
43
44  $rc->value;
45
46=head1 DESCRIPTION
47
48Senna::RC is a simple wrapper around sen_rc that allows you to evaluate
49results from Senna functions in Perl-ish boolean context, like
50
51  if ($index->insert($query)) {
52    ...
53  }
54
55Or, you can choose to access the internal sen_rc value:
56
57  my $rc = $index->insert($query);
58  if ($rc->value == SEN_SUCCESS) {
59    ...
60  }
61
62=head1 METHODS
63
64=head2 new
65
66Creates a new Senna::RC object
67
68=head2 value
69
70Returns the internal sen_rc value
71
72=cut
Note: See TracBrowser for help on using the browser.