Same/Cache.pm

filter: Statementstmt 88.2% 30 / 34 Branchbran 33.3% 2 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 77.7% 42 / 54 CC 5 SCAR 9.8
CC
5
Cov
77%
get
5.0
new
2.1
BEGIN
1.0
CRAP 2.7
« Same/Util.pm ↑ Summary Same/ChunkedSource.pm »
1 =head1 NAME
2  
3 Text::Same::Cache
4  
5 =head1 DESCRIPTION
6  
7 A (planned) cache of ChunkedSource objects. For now there is just one method:
8 get(), which returns a ChunkedSource object for a particular file.
9  
10 =head1 SYNOPSIS
11  
12 my $cache = new Text::Same::Cache();
13 my $chunked_source = $cache->get($file);
14  
15 =head1 METHODS
16  
17 See below. Methods private to this module are prefixed by an
18 underscore.
19  
20 =cut
21  
22 package Text::Same::Cache;
23  
24 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 $VERSION = '0.07';
30  
31 4 ▶use Text::Same::FileChunkedSource;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 =head2 new
34  
35 Title : new
36 Usage : $cache = new Text::Same::Cache();
37 Function: return a new, empty cache
38  
39 =cut
40  
41 sub new
42 37 ▶{
Subroutine new: called CC=2 SCAR=7.6
Pod documented
43 37 my $self = shift;
44 37 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0370
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
45 37 return bless {}, $class;
46 }
47  
48 =head2 get
49  
50 Title : get
51 Usage : my $chunked_source = $cache->get($file);
52 Function: return a ChunkedSource object for the given file, possibly getting
53 the ChunkedSource details from a cache
54  
55 =cut
56  
57 sub get
58 72 ▶{
Subroutine get: called CC=4 SCAR=16.1
Pod documented
59 72 my $self = shift;
60  
61 72 my $filename = shift;
62 72 my @lines = ();
63  
64 72 local $/ = "\n";
65 72 ▶ if ($filename =~ /(rcs|svn|co).*\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /(rcs|svn|co).*\|/) { } 0 72 72
66 0 ▶ open F, "$filename" or die "$!: $filename\n";
Branch: 1 branch
BranchTrueFalseTotal
open F, "$filename" or die "$!: $filename\n" 0 0 0
67  
68 0 @lines = map {chomp; $_} (<F>);
69 } else {
70 72 ▶ open F, "<$filename" or die "$!: $filename\n";
Branch: 1 branch
BranchTrueFalseTotal
open F, "<$filename" or die "$!: $filename\n" 72 0 72
71 72 @lines = map {chomp; $_} (<F>);
72 }
73 72 return new Text::Same::FileChunkedSource(name=>$filename, chunks=>\@lines);
74 }
75  
76 =head1 AUTHOR
77  
78 Kim Rutherford <kmr+same@xenu.org.uk>
79  
80 =head1 COPYRIGHT & LICENSE
81  
82 Copyright 2005,2006 Kim Rutherford. All rights reserved.
83  
84 This program is free software; you can redistribute it and/or modify it
85 under the same terms as Perl itself.
86  
87 =head1 DISCLAIMER
88  
89 This module is provided "as is" without warranty of any kind. It
90 may redistributed under the same conditions as Perl itself.
91  
92 =cut
93  
94 4 1;
« Same/Util.pm ↑ Summary Same/ChunkedSource.pm »