File Coverage

blib/lib/Darcs/Inventory.pm
Criterion Covered Total %
statement 41 41 100.0
branch 16 20 80.0
condition 9 13 69.2
subroutine 9 9 100.0
pod 6 6 100.0
total 81 89 91.0


line stmt bran cond sub pod time code
1             # Copyright (c) 2007-2012 David Caldwell, All Rights Reserved. -*- perl -*-
2              
3 3     3   48037 package Darcs::Inventory; use strict; use warnings;
  3     3   8  
  3         97  
  3         16  
  3         5  
  3         127  
4             our $VERSION = '1.7';
5              
6 3     3   1659 use Darcs::Inventory::Patch;
  3         9  
  3         31  
7              
8             sub read($) {
9 5     5 1 35 my ($filename) = @_;
10 5         28 my (@patch, $patch);
11 5 50       407 open INV, "<", $filename or return undef;
12 5         221 while () {
13 116 50 33     394 next if /^pristine:$/ && !defined $patch;
14 116 100 66     441 $patch[-1] .= "\n$1" if /^(hash: .*)$/ && !defined $patch;
15 116 100 100     495 (push(@patch, $patch . ($1||"")), undef $patch) if s/^(.*\*[-*]\d{14})?\]//;
16 116 100 100     600 $patch = '' if !defined $patch && s/^\s*\[//;
17 116 100       592 $patch .= $_ if defined $patch;
18             }
19 5         59 close INV;
20 5         22 \@patch;
21             }
22              
23             sub load($$) {
24 5     5 1 8460 my ($class, $filename) = @_;
25 5         74 my $patch = Darcs::Inventory::read($filename);
26 5 50       24 return undef unless $patch;
27 5         16 bless { patches => [map { new Darcs::Inventory::Patch($_) } @$patch],
  27         176  
28             file => $filename }, $class;
29             }
30              
31             sub new($$) {
32 3     3 1 100654 my ($class, $repo) = @_;
33              
34 3         6 my $repo_format = eval {
35 3         17 local $/;
36 3 100       201 open FORMAT, '<', "$repo/_darcs/format" or return "old";
37 2         69 my $f = ;
38 2         40 close FORMAT;
39 2         10 $f
40             };
41 3 100       31 my $inventory_file = $repo_format =~ /hashed/ ? "$repo/_darcs/hashed_inventory" : "$repo/_darcs/inventory";
42 3         20 my $inventory = $class->load($inventory_file);
43 3 50       18 return undef unless $inventory;
44 3         9 $inventory->{format} = $repo_format;
45 3         10 $inventory;
46             }
47              
48 3   50 3 1 46 sub format($) { return $_[0]->{format} || "unknown" };
49 3     3 1 260 sub file($) { return $_[0]->{file} };
50 5     5 1 1788 sub patches($) { return @{$_[0]->{patches}} };
  5         32  
51              
52             1;
53             __END__