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