File Coverage

blib/lib/Data/Localize/Storage/MongoDB.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Data::Localize::Storage::MongoDB;
2 1     1   1088 use Any::Moose;
  0            
  0            
3             use MongoDB;
4              
5             with 'Data::Localize::Storage';
6              
7             has 'database' => ( is => 'ro', isa => 'MongoDB::Database', required => 1 );
8             has 'collection' => (
9             is => 'ro',
10             isa => 'MongoDB::Collection',
11             lazy => 1,
12             default => sub {
13             my $self = shift;
14             $self->database->get_collection( $self->lang );
15             }
16             );
17              
18             sub is_volitile { 0 }
19              
20             sub get {
21             my ( $self, $key ) = @_;
22             my $result = $self->collection->find_one({ _id => $key });
23             return () unless $result;
24             return $result->{'msg'};
25             }
26              
27             sub set {
28             my ( $self, $key, $value ) = @_;
29             $self->collection->save({ _id => $key, msg => $value }, { safe => 1 });
30             return;
31             }
32              
33             __PACKAGE__->meta->make_immutable();
34              
35             no Any::Moose; 1;
36              
37             # ABSTRACT: A MongoDB storage backend for Data::Localize
38              
39              
40             __END__
41             =pod
42              
43             =head1 NAME
44              
45             Data::Localize::Storage::MongoDB - A MongoDB storage backend for Data::Localize
46              
47             =head1 VERSION
48              
49             version 0.001
50              
51             =head1 SYNOPSIS
52              
53             use Data::Localize::Storage::MongoDB;
54              
55             my $conn = MongoDB::Connection->new( host => 'localhost' );
56              
57             my $loc = Data::Localize->new;
58             $loc->add_localizer(
59             class => 'Gettext',
60             path => 't/001-basic/*.po',
61             storage_class => 'MongoDB',
62             storage_args => {
63             database => $conn->get_database('i18n')
64             }
65             );
66              
67             $loc->set_languages('ja');
68             print $loc->localize('Hello, stranger!', '牧大輔');
69              
70             $loc->set_languages('en');
71             print $loc->localize_for('Hello, stranger!', 'Stevan');
72              
73             =head1 DESCRIPTION
74              
75             This is a simple L<MongoDB> storage backend for L<Data::Localize>.
76              
77             =head1 METHODS
78              
79             =head2 get
80              
81             This is used internally by L<Data::Localize>.
82              
83             =head2 set
84              
85             This is used internally by L<Data::Localize>.
86              
87             =head1 AUTHOR
88              
89             Stevan Little <stevan.little@iinteractive.com>
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             This software is copyright (c) 2011 by Infinity Interactive, Inc..
94              
95             This is free software; you can redistribute it and/or modify it under
96             the same terms as the Perl 5 programming language system itself.
97              
98             =cut
99