Dump/Config.pm

filter: Statementstmt 48.7% 19 / 39 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 100% 1 / 1 totaltotal 40.0% 24 / 60 CC 7 SCAR 22.6
CC
7
Cov
39%
_get_config
20.0
_restore
12.0
run
6.0
CRAP 9.6
« Dump/Restore.pm ↑ Summary
1  
2 package Redis::Dump::Config;
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 with 'MooseX::Getopt';
7  
8 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Redis 1.904;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: It's a simple way to dump and backup config from redis-server
12 1 our $VERSION = '0.016'; # VERSION
13  
14 has _conn => (
15 is => 'ro',
16 isa => 'Redis',
17 init_arg => undef,
18 lazy => 1,
19 0 ▶ default => sub { Redis->new( server => shift->server ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 1 );
21  
22 0 ▶sub _get_config {
Subroutine _get_config: not called CC=4 SCAR=30.0
23 0 my $self = shift;
24 0 my %cf;
25 0 my $filter = $self->filter;
26 0 ▶ my @configs = $self->_conn->config( 'get', $filter ? "*$filter*" : '*' );
Branch: 1 branch
BranchTrueFalseTotal
$filter ? : 0 0 0
27 0 ▶ for ( my $loop = 0; $loop < scalar(@configs) / 2; $loop++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop < scalar(@configs) / 2) 0 0 0
28 0 my $name = $configs[ $loop * 2 ];
29 0 ▶ my $value = $configs[ ( $loop * 2 ) + 1 ] || '';
Condition0%0/2
$configs[$loop * 2 + 1] || ''
l!l
00
MC/DC0%0/1
$configs[$loop * 2 + 1] || ''
$configs[$loop * 2 + 1]
Truth table0%0/2
A
A= $configs[$loop * 2 + 1]
Aresult
11
00
30 0 $cf{$name} = $value;
31 }
32  
33 0 return %cf;
34 }
35  
36 0 ▶sub _restore {
Subroutine _restore: not called CC=3 SCAR=24.8
37 0 my $self = shift;
38 0 my %keys = %{ from_json( $self->restore->slurp ) };
39 0 foreach my $key ( keys %keys ) {
40 0 ▶ my $value = $keys{$key} || "";
Condition0%0/2
$keys{$key} || ''
l!l
00
MC/DC0%0/1
$keys{$key} || ''
$keys{$key}
Truth table0%0/2
A
A= $keys{$key}
Aresult
11
00
41 0 warn "config set $key $value";
42 0 $self->_conn->config( 'set', $key, $value );
43 }
44 }
45  
46  
47 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
48 0 my $self = shift;
49  
50 0 ▶ $self->_restore if $self->has_restore;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_restore 0 0 0
51  
52 0 return $self->_get_config;
53 }
54  
55  
56 1 has server => (
57 is => 'ro',
58 isa => 'Str',
59 default => '127.0.0.1:6379',
60 documentation => 'Host:Port of redis server (ex. 127.0.0.1:6379)'
61 );
62  
63  
64 1 has filter => (
65 is => 'ro',
66 isa => 'Str',
67 default => '',
68 predicate => 'has_filter',
69 documentation => 'String to filter keys stored in redis server'
70 );
71  
72  
73 1 has restore => (
74 is => 'ro',
75 isa => 'Path::Class::File',
76 coerce => 1,
77 predicate => 'has_restore',
78 documentation => 'Restore a config redis server to the server',
79 );
80  
81 1 1;
82  
83  
84  
85 =pod
86  
87 =head1 NAME
88  
89 Redis::Dump::Config - It's a simple way to dump and backup config from redis-server
90  
91 =head1 VERSION
92  
93 version 0.016
94  
95 =head1 SYNOPSIS
96  
97 use Redis::Dump::Config;
98 use Data::Dumper;
99  
100 my $dump = Redis::Dump::Config->new({ server => '127.0.0.6379', filter => 'foo' });
101  
102 print Dumper( \$dump->run );
103  
104 =head1 DESCRIPTION
105  
106 It's a simple way to dump config from redis-server in JSON format or any format
107 you want.
108  
109 =head1 COMMAND LINE API
110  
111 This class uses L<MooseX::Getopt> to provide a command line api. The command line options map to the class attributes.
112  
113 =head1 METHODS
114  
115 =head2 new_with_options
116  
117 Provided by L<MooseX::Getopt>. Parses attributes init args from @ARGV.
118  
119 =head2 run
120  
121 Perfomas the actual dump.
122  
123 =head1 ATTRIBUTES
124  
125 =head2 server
126  
127 Host:Port of redis server, example: 127.0.0.1:6379.
128  
129 =head2 filter
130  
131 String to filter keys stored in redis server.
132  
133 =head2 restore
134  
135 Restore a config redis server to the server.
136  
137 =head1 DEVELOPMENT
138  
139 Redis::Dump is a open source project for everyone to participate. The code repository
140 is located on github. Feel free to send a bug report, a pull request, or a
141 beer.
142  
143 L<http://www.github.com/maluco/Redis-Dump>
144  
145 =head1 SEE ALSO
146  
147 L<Redis::Dump::Restore>, L<App::Redis::Dump>, L<App::Redis::Dump::Restore>
148  
149 =head1 SUPPORT
150  
151 You can find documentation for this module with the perldoc command.
152  
153 perldoc Redis::Dump
154  
155 You can also look for information at:
156  
157 =over 4
158  
159 =item * RT: CPAN's request tracker
160  
161 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Redis-Dump>
162  
163 =item * AnnoCPAN: Annotated CPAN documentation
164  
165 L<http://annocpan.org/dist/Redis-Dump>
166  
167 =item * CPAN Ratings
168  
169 L<http://cpanratings.perl.org/d/Redis-Dump>
170  
171 =item * Search CPAN
172  
173 L<http://search.cpan.org/dist/Redis-Dump>
174  
175 =back
176  
177 =head1 AUTHOR
178  
179 Thiago Rondon <thiago@nsms.com.br>
180  
181 =head1 COPYRIGHT AND LICENSE
182  
183 This software is copyright (c) 2011 by Thiago Rondon.
184  
185 This is free software; you can redistribute it and/or modify it under
186 the same terms as the Perl 5 programming language system itself.
187  
188 =cut
189  
190  
191 __END__
« Dump/Restore.pm ↑ Summary