File Coverage

blib/lib/Shipwright/Backend.pm
Criterion Covered Total %
statement 27 28 96.4
branch 8 10 80.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Shipwright::Backend;
2              
3 6     6   1239 use warnings;
  6         11  
  6         197  
4 6     6   43 use strict;
  6         8  
  6         122  
5 6     6   1418 use UNIVERSAL::require;
  6         4546  
  6         43  
6 6     6   142 use Shipwright::Util;
  6         10  
  6         1557  
7              
8             sub new {
9 17     17 1 19463 my $class = shift;
10 17         48 my %args = @_;
11              
12 17 100       62 confess_or_die 'need repository arg' unless exists $args{repository};
13              
14 16         51 $args{repository} =~ s/^\s+//;
15 16         38 $args{repository} =~ s/\s+$//;
16              
17             # exception for svk repos, they can start with //
18 16 100       48 if ( $args{repository} =~ m{^//} ) {
19 1         3 $args{repository} = 'svk:'. $args{repository};
20             }
21              
22 16         23 my $backend;
23 16 100       74 if ( $args{repository} =~ /^([a-z]+)(?:\+([a-z]+))?:/ ) {
24 12         32 ($backend) = $1;
25             } else {
26 4         14 confess_or_die "invalid repository, doesn't start with xxx: or xxx+yyy:";
27             }
28              
29 12         43 my $module = find_module(__PACKAGE__, $backend);
30 12 50       36 unless ( $module ) {
31 0         0 confess_or_die "Couldn't find backend implementing '$backend'";
32             }
33              
34             $module->require
35 12 50       77 or confess_or_die "Couldn't load module '$module'"
36             ." implementing backend '$backend': $@";
37 12         327 return $module->new(%args);
38             }
39              
40             1;
41              
42             __END__