File Coverage

perllib/Arch/Backend.pm
Criterion Covered Total %
statement 43 55 78.1
branch 7 20 35.0
condition 9 27 33.3
subroutine 22 23 95.6
pod 16 16 100.0
total 97 141 68.7


line stmt bran cond sub pod time code
1             # Arch Perl library, Copyright (C) 2005 Mikhael Goikhman
2             #
3             # This program is free software; you can redistribute it and/or modify
4             # it under the terms of the GNU General Public License as published by
5             # the Free Software Foundation; either version 2 of the License, or
6             # (at your option) any later version.
7             #
8             # This program is distributed in the hope that it will be useful,
9             # but WITHOUT ANY WARRANTY; without even the implied warranty of
10             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11             # GNU General Public License for more details.
12             #
13             # You should have received a copy of the GNU General Public License
14             # along with this program; if not, write to the Free Software
15             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16              
17 37     37   679 use 5.005;
  37         130  
  37         1690  
18 37     37   225 use strict;
  37         73  
  37         1670  
19              
20             package Arch::Backend;
21              
22 37     37   1891 use Arch::Util;
  37         119  
  37         1601  
23              
24 37     37   803 use Exporter;
  37         292  
  37         1995  
25 37     37   210 use vars qw(@ISA @EXPORT_OK $EXE $NAME $VRSN $CACHE_CONFIG);
  37         82  
  37         7307  
26              
27             @ISA = qw(Exporter);
28             @EXPORT_OK = qw(
29             arch_backend arch_backend_name arch_backend_version is_baz is_tla
30             has_archive_setup_cmd has_file_diffs_cmd has_register_archive_name_arg
31             has_tree_version_dir_opt has_tree_id_cmd has_set_tree_version_cmd
32             has_cache_feature get_cache_config
33             has_commit_version_arg has_commit_files_separator
34             has_revlib_patch_set_dir
35             );
36              
37             BEGIN {
38 37   50 37   43533 $EXE ||= $ENV{ARCH_BACKEND} || $ENV{TLA} || $ENV{BAZ} || "tla";
      33        
39             }
40              
41             sub arch_backend (;$) {
42 3 100   3 1 41 $EXE = shift if $_[0];
43 3         25 return $EXE;
44             }
45              
46             sub _parse_name_version () {
47 1   50 1   7 my ($line1) = Arch::Util::run_tla("--version") || "";
48 1 50       34 if ($line1 =~ /\b(tla|baz)(?:--.*--)?.*(\d+\.\d+(?:.\d+)?)/) {
49 0         0 ($NAME, $VRSN) = ($1, $2);
50             } else {
51 1         10 ($NAME, $VRSN) = ("tla", "1.3");
52 1 50       13 if ($EXE =~ /(tla|baz)(?:-(\d\.\d+(?:.\d+)?))/) {
53 0         0 $NAME = $1;
54 0 0       0 $VRSN = $2 if $2;
55             }
56 1 50       27 warn "Can't parse '$EXE --version' and determine arch backend name/version.\n"
57             . "Please check \$ARCH_BACKEND and optionally notify arch-perl developers.\n"
58             . "Assuming ($NAME, $VRSN). Set \$ARCH_PERL_QUIET to disable this warning.\n"
59             unless $ENV{ARCH_PERL_QUIET};
60             }
61             #print "arch_backend name and version: ($NAME, $VRSN)\n";
62 1         42 return ($NAME, $VRSN);
63             }
64              
65             sub arch_backend_name () {
66 13   66 13 1 129 return $NAME ||= (_parse_name_version)[0];
67             }
68              
69             sub arch_backend_version () {
70 2   33 2 1 34 return $VRSN ||= (_parse_name_version)[1];
71             }
72              
73             sub is_baz () {
74 5     5 1 11 return arch_backend_name() eq "baz";
75             }
76              
77             sub is_tla () {
78 7     7 1 21 return arch_backend_name() eq "tla";
79             }
80              
81             sub has_archive_setup_cmd () {
82 1     1 1 4 return is_tla();
83             }
84              
85             sub has_file_diffs_cmd () {
86 1   33 1 1 3 return is_tla() && arch_backend_version() =~ /^1\.[12]/;
87             }
88              
89             sub has_register_archive_name_arg () {
90 1     1 1 3 return is_tla();
91             }
92              
93             sub has_tree_version_dir_opt () {
94 1     1 1 8 return is_baz();
95             }
96              
97             sub has_tree_id_cmd () {
98 1     1 1 4 return is_baz();
99             }
100              
101             sub has_set_tree_version_cmd () {
102 1     1 1 4 return is_tla();
103             }
104              
105             sub has_cache_feature () {
106 2     2 1 7 return is_baz();
107             }
108              
109             sub get_cache_config () {
110 1 50   1 1 6 unless ($CACHE_CONFIG) {
111 1         6 my $output = "";
112              
113 1 50       3 if (has_cache_feature()) {
114             # baz-1.1 .. baz-1.3.2 prints on stderr instead of stdout
115 0         0 my $baz_is_buggy = 1;
116 0 0       0 if ($baz_is_buggy) {
117 0         0 my $file = "$ENV{HOME}/.arch-params/=arch-cache";
118 0 0       0 if (-f $file) {
119 0         0 my $dir = Arch::Util::load_file($file);
120 0         0 $dir =~ s/\r?\n.*//s;
121 0 0 0     0 $output = "Location: $dir\n" if $dir && -d $dir;
122             }
123             } else {
124 0         0 $output = Arch::Util::run_tla("cache-config");
125             }
126             }
127              
128 1   50     12 my $location = $output =~ /^Location: (.*)/m && $1 || undef;
129 1         82 $CACHE_CONFIG = {
130             dir => $location,
131             };
132             }
133 1         15 return $CACHE_CONFIG;
134             }
135              
136             sub has_commit_version_arg () {
137 2   33 2 1 4 return is_tla() || is_baz() && arch_backend_version() =~ /^1\.[0123]/;
138             }
139              
140             sub has_commit_files_separator () {
141 1     1 1 3 return has_commit_version_arg();
142             }
143              
144             sub has_revlib_patch_set_dir () {
145 0   0 0 1   return is_tla() || is_baz() && arch_backend_version() =~ /^1\.[0123]/;
146             }
147              
148             1;
149              
150             __END__