File: Null.pm

package info (click to toggle)
libdbm-deep-perl 2.0008-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 884 kB
  • sloc: perl: 7,383; sql: 36
file content (49 lines) | stat: -rw-r--r-- 1,169 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package DBM::Deep::Null;

use 5.008_004;

use strict;
use warnings FATAL => 'all';

=head1 NAME

DBM::Deep::Null - NULL object

=head1 PURPOSE

This is an internal-use-only object for L<DBM::Deep>. It acts as a NULL object
in the same vein as MARCEL's L<Class::Null>. I couldn't use L<Class::Null>
because DBM::Deep needed an object that always evaluated as undef, not an
implementation of the Null Class pattern.

=head1 OVERVIEW

It is used to represent null sectors in DBM::Deep.

=cut

use overload
    'bool'   => sub { undef },
    '""'     => sub { undef },
    '0+'     => sub { 0 },
   ('cmp'    => 
    '<=>'    => sub {
                  return 0 if !defined $_[1] || !length $_[1];
                  return $_[2] ? 1 : -1;
                }
   )[0,2,1,2], # same sub for both ops
    '%{}'    => sub {
                  require Carp;
                  Carp::croak("Can't use a stale reference as a HASH");
                },
    '@{}'    => sub {
                  require Carp;
                  Carp::croak("Can't use a stale reference as an ARRAY");
                },
    fallback => 1,
    nomethod => 'AUTOLOAD';

sub AUTOLOAD { return; }

1;
__END__