Config.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 50.0% 2 / 4 totaltotal 93.3% 84 / 90 CC 9 SCAR 7.4
CC
9
Cov
94%
_build_from_config
4.0
BUILD
3.1
save
3.0
CRAP 2.1
« Config/Reader.pm ↑ Summary Config/Group.pm »
1 package Gitosis::Config;
2 4 our $VERSION = '0.06';
3 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooseX::Types::Path::Class qw(File);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use MooseX::AttributeHelpers;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Gitosis::Config::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Gitosis::Config::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Gitosis::Config::Group;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 has file => (
12 isa => File,
13 coerce => 1,
14 is => 'rw',
15 );
16  
17 4 has [qw(gitweb daemon loglevel repositories)] => (
18 isa => 'Maybe[Str]',
19 is => 'rw',
20 );
21  
22 4 has groups => (
23 metaclass => 'Collection::Array',
24 isa => 'ArrayRef[Gitosis::Config::Group]',
25 is => 'ro',
26 auto_deref => 1,
27 lazy_build => 1,
28 provides => {
29 push => 'add_group',
30 find => 'find_group',
31 },
32 );
33  
34 2 ▶sub find_group_by_name {
Subroutine find_group_by_name: called CC=1 SCAR=0.0
Pod undocumented
35 2 my ( $self, $arg ) = @_;
36 2 ▶ $self->find_group( sub { $_[0]->name eq $arg } );
Subroutine __ANON__: called CC=1 SCAR=0.0
37 }
38  
39 4 ▶sub _build_groups { [] }
Subroutine _build_groups: called CC=1 SCAR=0.0
40  
41 6 ▶around 'add_group' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
42 6 my ( $next, $self, $group ) = @_;
43 6 ▶ $group = Gitosis::Config::Group->new($group) unless ( blessed $group);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($group) 6 0 6
44 6 $self->$next($group);
45 4 };
46  
47 4 has repos => (
48 metaclass => 'Collection::Array',
49 isa => 'ArrayRef[HashRef]',
50 is => 'ro',
51 auto_deref => 1,
52 lazy_build => 1,
53 provides => { push => 'add_repo', }
54 );
55  
56 4 ▶sub _build_repos { [] }
Subroutine _build_repos: called CC=1 SCAR=0.0
57  
58 #
59 # METHODS
60 #
61  
62 10 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
63 10 Gitosis::Config::Writer->write_string( $_[0] );
64 }
65  
66 2 ▶sub save {
Subroutine save: called CC=3 SCAR=11.1
Pod documented
67 2 my ($self) = @_;
68 2 ▶ die 'Must have a filename, please set file()' unless $self->file;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->file 1 1 2
69 1 ▶ $self->file->openw->print( $self->to_string ) or die "$!";
Branch: 1 branch
BranchTrueFalseTotal
$self->file->openw->print($self->to_string) or die "$!" 1 0 1
70  
71 }
72  
73 #
74 # Constructor Hack
75 #
76  
77 4 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.2
Pod undocumented
78 4 my ( $self, $args ) = @_;
79  
80 4 ▶ if ( exists $args->{config} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"config"}) 0 4 4
81 0 return $self->_build_from_config( $args->{config} );
82 }
83  
84 4 ▶ if ( exists $args->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"file"}) 2 2 4
85 2 $self->file( $args->{file} );
86 2 my $cfg = Gitosis::Config::Reader->read_file( $args->{file} );
87 2 return $self->_build_from_config($cfg);
88 }
89 }
90  
91 2 ▶sub _build_from_config {
Subroutine _build_from_config: called CC=4 SCAR=13.9
92 2 my ( $self, $cfg ) = @_;
93 2 for my $attr (qw(gitweb daemon loglevel repositories)) {
94 8 $self->$attr( $cfg->{gitosis}{$attr} );
95 }
96 2 for my $name ( grep { $_ =~ /^group/ } keys %$cfg ) {
97 4 my $group = $cfg->{$name};
98 4 ( $group->{name} = $name ) =~ s/^group\s+//;
99 4 $self->add_group($group);
100 }
101  
102 2 for my $name ( grep { $_ =~ /^repo/ } keys %$cfg ) {
103 1 my $repo = $cfg->{$name};
104 1 ( $repo->{name} = $name ) =~ s/^repo\s+//;
105 1 $self->add_repo($repo);
106 }
107 }
108  
109 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 4 1;
111 __END__
« Config/Reader.pm ↑ Summary Config/Group.pm »