MooseX/Storage/IO/GitStore.pm

filter: Statementstmt 50.0% 13 / 26 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 3 / 9 Podpod 100% 2 / 2 totaltotal 27.2% 18 / 66 SCAR 34.3
CC
8
Cov
29%
load
42.0
__ANON__
6.0
store
6.0
CRAP 31.0
« GitStore.pm ↑ Summary GitStore/Revision.pm »
1 package MooseX::Storage::IO::GitStore;
2 BEGIN {
3 1 ▶ $MooseX::Storage::IO::GitStore::AUTHORITY = 'cpan:YANICK';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5 #ABSTRACT: Save Moose objects in your GitStore
6 1 $MooseX::Storage::IO::GitStore::VERSION = '0.16';
7 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 requires 'thaw';
10 1 requires 'freeze';
11  
12 1 has git_repo => (
13 traits => [ 'DoNotSerialize' ],
14 is => 'ro',
15 isa => 'Str',
16 required => 0,
17 );
18  
19 has gitstore => (
20 traits => [ 'DoNotSerialize' ],
21 is => 'ro',
22 isa => 'GitStore|Undef',
23 lazy => 1,
24 0 ▶ default => sub { $_[0]->git_repo && _basic_store($_[0]->git_repo); },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->git_repo and _basic_store($_[0]->git_repo) 0 0 0
25 1 );
26  
27 sub _basic_store {
28 GitStore->new( repo => $_[0], autocommit => 1,
29 0 ▶ serializer => sub { $_[2] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 ▶ deserializer => sub { $_[2] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 ▶ );
Subroutine _basic_store: not called CC=1 SCAR=6.9
32 }
33  
34 sub load {
35 0 ▶ my ( $class, $filename, %args ) = @_;
Subroutine load: not called CC=6 SCAR=37.4
Pod documented
36  
37 0 ▶ if( ref $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 0 0
38 0 ▶ $args{git_repo} ||= $class->git_repo;
Condition0%0/3
$args{"git_repo"} ||= $class->git_repo
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"git_repo"} ||= $class->git_repo
$args{"git_repo"} $class->git_repo
Truth table0%0/3
A ||= B
A= $args{"git_repo"}B= $class->git_repo
ABresult
1X1
011
000
39 0 ▶ $args{gitstore} ||= $class->gitstore;
Condition0%0/3
$args{"gitstore"} ||= $class->gitstore
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"gitstore"} ||= $class->gitstore
$args{"gitstore"} $class->gitstore
Truth table0%0/3
A ||= B
A= $args{"gitstore"}B= $class->gitstore
ABresult
1X1
011
000
40 }
41  
42 0 ▶ $args{inject}{git_repo} ||= $args{git_repo};
Condition0%0/3
$args{"inject"}{"git_repo"} ||= $args{"git_repo"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"inject"}{"git_repo"} ||= $args{"git_repo"}
$args{"inject"}{"git_repo"} $args{"git_repo"}
Truth table0%0/3
A ||= B
A= $args{"inject"}{"git_repo"}B= $args{"git_repo"}
ABresult
1X1
011
000
43 0 ▶ $args{gitstore} ||= _basic_store($args{git_repo});
Condition0%0/3
$args{"gitstore"} ||= _basic_store($args{"git_repo"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"gitstore"} ||= _basic_store($args{"git_repo"})
$args{"gitstore"} _basic_store($args{"git_repo"})
Truth table0%0/3
A ||= B
A= $args{"gitstore"}B= _basic_store($args{"git_repo"})
ABresult
1X1
011
000
44 0 $class->thaw($args{gitstore}->get($filename),%args);
45 }
46  
47 sub store {
48 0 ▶ my ( $self, $filename, %args ) = @_;
Subroutine store: not called CC=2 SCAR=17.9
Pod documented
49 0 ▶ ($self->gitstore || _basic_store($args{git_repo}))->set( $filename => $self->freeze(%args) );
Condition0%0/3
$self->gitstore || _basic_store($args{'git_repo'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->gitstore || _basic_store($args{'git_repo'})
$self->gitstore _basic_store($args{'git_repo'})
Truth table0%0/3
A || B
A= $self->gitstoreB= _basic_store($args{'git_repo'})
ABresult
1X1
011
000
50 }
51  
52 1 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 1 1;
55  
56 __END__
57  
58 =pod
59  
60 =encoding UTF-8
61  
62 =head1 NAME
63  
64 MooseX::Storage::IO::GitStore - Save Moose objects in your GitStore
65  
66 =head1 VERSION
67  
68 version 0.16
69  
70 =head1 SYNOPSIS
71  
72 package Point;
73 use Moose;
74 use MooseX::Storage;
75  
76 with Storage( format => 'YAML', io => 'GitStore');
77  
78 has 'x' => (is => 'rw', isa => 'Int');
79 has 'y' => (is => 'rw', isa => 'Int');
80  
81 1;
82  
83 my $p = Point->new(x => 10, y => 10);
84  
85 ## methods to load/store a class
86 ## on the file system
87  
88 $p->store('my_point', git_repo => './store');
89  
90 my $p2 = Point->load('my_point', git_repo => './store');
91  
92 =head1 ATTRIBUTES
93  
94 The role adds two attributes to the class, C<git_repo> and C<gitstore>.
95  
96 =head2 git_repo
97  
98 The optional path to the git repository where the object will be stored.
99  
100 =head2 gitstore
101  
102 The L<GitStore> object used by the storage system. If not specified, it will
103 be created using I<git_repo>, and will have I<autocommit> set to 1.
104  
105 =head1 METHODS
106  
107 =over 4
108  
109 =item B<load ($filename, git_repo => $path)>
110  
111 Load the object associated with I<$filename>. I<$path> can be omited if used
112 from an object instead of as a class method.
113  
114 =item B<store ($filename, git_repo => $path)>
115  
116 Save the object as I<$filename>. I<$path> can be omited if used
117 from an object instead of as a class method.
118  
119 =back
120  
121 =head1 SEE ALSO
122  
123 L<MooseX::Storage>
124  
125 =head1 AUTHORS
126  
127 =over 4
128  
129 =item *
130  
131 Fayland Lam <fayland@gmail.com>
132  
133 =item *
134  
135 Yanick Champoux <yanick@cpan.org>
136  
137 =back
138  
139 =head1 COPYRIGHT AND LICENSE
140  
141 This software is copyright (c) 2015 by Fayland Lam <fayland@gmail.com>.
142  
143 This is free software; you can redistribute it and/or modify it under
144 the same terms as the Perl 5 programming language system itself.
145  
146 =cut
« GitStore.pm ↑ Summary GitStore/Revision.pm »