File Coverage

blib/lib/YAML/MLDBM.pm
Criterion Covered Total %
statement 15 16 93.7
branch 1 2 50.0
condition 1 2 50.0
subroutine 4 4 100.0
pod 0 1 0.0
total 21 25 84.0


line stmt bran cond sub pod time code
1             package YAML::MLDBM;
2             $VERSION = '0.10';
3              
4 1     1   33000 use MLDBM (undef, 'YAML');
  1         4057  
  1         7  
5 1     1   32 use Fcntl;
  1         2  
  1         302  
6 1     1   6 use Carp;
  1         6  
  1         164  
7              
8             sub new {
9 1     1 0 15 my $class = shift;
10 1         2 my $db_file = shift;
11 1   50     9 my $mode = shift || 0640;
12            
13 1         2 my %hash;
14             tie %hash, 'MLDBM', $db_file, O_CREAT|O_RDWR, $mode
15 1 50       11 or do {
16 0         0 confess "Can't make a tied hash for you: $!";
17             };
18 1         2338 return \%hash;
19             }
20              
21             1;
22              
23             =head1 NAME
24              
25             YAML::MLDBM - Use tied hash db-s with Python and Ruby
26              
27             =head1 SYNOPSIS
28              
29             use YAML::MLDBM;
30              
31             my $h = YAML::MLDBM->new('./my_dbm_file');
32              
33             $h->{'@INC'} = \@INC;
34             $h->{'%ENV'} = \%ENV;
35              
36             use Data::Dumper;
37             print Dumper $h;
38              
39             =head1 DESCRIPTION
40              
41             This module is similar to MLDBM except that it stores data internally as
42             YAML, instead of Data::Dumper or Storable. By doing this, you can create
43             tied hash DBM databases that can be used seamlessly in Python or Ruby
44             applications. That's because those languages also have YAML and DBM
45             modules. As other languages get YAML support, you should be able to use
46             YAML::MLDBM with them as well.
47              
48             This module is a wrapper around MLDBM, but you open a DBM file using the
49             new() method, instead of using a tie. new() will return a reference to a
50             tied hash.
51              
52             You can also use YAML as a serialization method for MLDBM itself:
53              
54             use MLDBM qw(SDBM_File YAML);
55             use Fcntl;
56            
57             tie %h, 'MLDBM', './my_dbm_file', O_CREAT|O_RDWR, 0640 or die $!;
58            
59             $h{'@INC'} = \@INC;
60             $h{'%ENV'} = \%ENV;
61            
62             use Data::Dumper;
63             print Dumper \%h;
64              
65             This has the same affect, but is more verbose. It does offer you more
66             control if you want it though.
67              
68             =head1 SEE ALSO
69              
70             See L, L and L for more information.
71              
72             =head1 AUTHOR
73              
74             Brian Ingerson
75              
76             =head1 COPYRIGHT
77              
78             Copyright (c) 2003 Brian Ingerson. All rights reserved.
79              
80             This program is free software; you can redistribute it and/or modify it
81             under the same terms as Perl itself.
82              
83             =cut