File Coverage

blib/lib/Sietima/MailStore.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Sietima::MailStore;
2 3     3   12504 use Moo::Role;
  3         8  
  3         19  
3 3     3   897 use Sietima::Policy;
  3         6  
  3         15  
4 3     3   24 use namespace::clean;
  3         6  
  3         14  
5              
6             our $VERSION = '1.0.5'; # VERSION
7             # ABSTRACT: interface for mail stores
8              
9              
10             requires 'store',
11             'retrieve_ids_by_tags','retrieve_by_tags','retrieve_by_id',
12             'remove','clear';
13              
14             1;
15              
16             __END__
17              
18             =pod
19              
20             =encoding UTF-8
21              
22             =head1 NAME
23              
24             Sietima::MailStore - interface for mail stores
25              
26             =head1 VERSION
27              
28             version 1.0.5
29              
30             =head1 DESCRIPTION
31              
32             This role defines the interface that all mail stores must adhere
33             to. It does not provide any implementation.
34              
35             =head1 REQUIRED METHODS
36              
37             =head2 C<store>
38              
39             my $id = $ms->store($email_mime_object,@tags);
40              
41             Must persistently store the given email message (as an L<<
42             C<Email::Simple> >> object or similar), associating it with the gives
43             tags (which must be strings). Must return a unique identifier for the
44             stored message. It is acceptable if identical messages are
45             indistinguishable by the storage.
46              
47             =head2 C<retrieve_by_id>
48              
49             my $email_mime_object = $ms->retrieve_by_id($id);
50              
51             Given an identifier returned by L<< /C<store> >>, this method must
52             return the email message (as an L<< C<Email::Simple> >> or L<<
53             C<Email::MIME> >> object).
54              
55             If the message has been deleted, or the identifier is not recognised,
56             this method must return C<undef> in scalar context.
57              
58             =head2 C<retrieve_ids_by_tags>
59              
60             my @ids = $ms->retrieve_ids_by_tags(@tags)->@*;
61              
62             Given a list of tags (which must be strings), this method must return
63             an arrayref containing the identifiers of all (and only) the messages
64             that were stored associated with (at least) all those tags. The order
65             of the returned identifiers is not important.
66              
67             If there are no messages associated with the given tags, this method
68             must return an empty arrayref.
69              
70             For example:
71              
72             my $id1 = $ms->store($msg1,'t1');
73             my $id2 = $ms->store($msg2,'t2');
74             my $id3 = $ms->store($msg3,'t1','t2');
75              
76             $ms->retrieve_ids_by_tags('t1') ==> [ $id3, $id1 ]
77             $ms->retrieve_ids_by_tags('t2') ==> [ $id2, $id3 ]
78             $ms->retrieve_ids_by_tags('t1','t2') ==> [ $id3 ]
79             $ms->retrieve_ids_by_tags('t3') ==> [ ]
80              
81             =head2 C<retrieve_by_tags>
82              
83             my @email_mime_objects = $ms->retrieve_by_tags(@tags)->@*;
84              
85             This method is similar to L<< /C<retrieve_ids_by_tags> >>, but it must
86             return an arrayref of hashrefs. For example:
87              
88             my $id1 = $ms->store($msg1,'t1');
89             my $id2 = $ms->store($msg2,'t2');
90             my $id3 = $ms->store($msg3,'t1','t2');
91              
92             $ms->retrieve_ids_by_tags('t1') ==> [
93             { id => $id3, mail => $msg3 },
94             { id => $id1, mail => $msg1 },
95             ]
96              
97             =head2 C<remove>
98              
99             $ms->remove($id);
100              
101             This method must remove the message corresponding to the given
102             identifier from the persistent storage. Removing a non-existent
103             message must succeed, and do nothing.
104              
105             =head2 C<clear>
106              
107             $ms->clear();
108              
109             This method must remove all messages from the persistent
110             storage. Clearing an empty store must succeed, and do nothing.
111              
112             =head1 AUTHOR
113              
114             Gianni Ceccarelli <dakkar@thenautilus.net>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2017 by Gianni Ceccarelli <dakkar@thenautilus.net>.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut