File Coverage

blib/lib/Tie/Hash/Abbrev/Smart.pm
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 22 25 88.0


line stmt bran cond sub pod time code
1             package Tie::Hash::Abbrev::Smart;
2              
3             =head1 NAME
4              
5             Tie::Hash::Abbrev::Smart - a hash which can be accessed using abbreviated keys
6              
7             =head1 SYNOPSIS
8              
9             use Tie::Hash::Abbrev::Smart;
10              
11             tie my %hash, 'Tie::Hash::Abbrev::Smart';
12              
13             %hash = ( sonntag =>0, montag =>1, dienstag=>2, mittwoch =>3,
14             donnerstag=>4, freitag=>5, samstag =>6,
15             sunday =>0, monday =>1, tuesday =>2, wednesday=>3,
16             thursday =>4, friday =>5, saturday=>6 );
17              
18             print $hash{do}; # will print "4"
19             print $hash{fr}; # will print "5"
20             print $hash{t}; # undef
21              
22             my @deleted = tied(%hash)->delete_abbrev(qw(do fr t));
23             # will delete elements "donnerstag", "freitag" and "friday";
24             @deleted will be (4,5,5)
25              
26             =head1 DESCRIPTION
27              
28             This module implements a subclass of L.
29             The contents of hashes tied to this class may be accessed via unambiguously
30             abbreviated keys.
31             (Please note, however, that this is not true for
32             L hash elements;
33             for that you can use L via the object
34             interface.)
35              
36             In contrast to L, an abbreviation is still considered to be
37             unambiguous even if more than one key starting with the respective string
38             exists, as long as all of the corresponding elements have identical (string)
39             values.
40              
41             =head1 BUGS
42              
43             None known so far.
44              
45             =head1 AUTHOR
46              
47             Martin H. Sluka
48             mailto:perl@sluka.de
49             http://martin.sluka.de/
50              
51             =head1 COPYRIGHT
52              
53             This program is free software; you can redistribute
54             it and/or modify it under the same terms as Perl itself.
55              
56             The full text of the license can be found in the
57             LICENSE file included with this module.
58              
59             =head1 SEE ALSO
60              
61             L
62              
63             =cut
64              
65 1     1   25405 use strict;
  1         4  
  1         39  
66 1     1   5 use vars '$VERSION';
  1         2  
  1         65  
67 1     1   535 use Tie::Hash::Abbrev; # for buggy base.pm in Perl 5.005_03
  1         3  
  1         30  
68 1     1   6 use base 'Tie::Hash::Abbrev';
  1         2  
  1         127  
69              
70             $VERSION = 0.01;
71              
72             sub equals {
73 49     49 0 78 my ( $self, $value0, $value1 ) = @_;
74 49 50 66     565 defined $value0 ? defined $value1 && $value0 eq $value1 : !defined $value1;
75             }
76              
77             1