add basic inflation wrapper and simple inflator
[dbsrgits/DBIx-Data-Store.git] / lib / DBIx / Data / Collection / Set / Wrapper / Inflate.pm
1 package DBIx::Data::Collection::Set::Wrapper::Inflate;
2
3 use strictures 1;
4
5 sub new {
6   my $proto = shift;
7   bless({ %{$_[0]} }, ref($proto)||$proto);
8 }
9
10 sub _inflator { shift->{inflator} }
11 sub _inner { shift->{inner} }
12
13 sub flatten {
14   my ($self) = @_;
15   map $self->_inflator->inflate($_), $self->_inner->flatten;
16 }
17
18 sub to_stream {
19   my ($self) = @_;
20   my $inflator = $self->_inflator;
21   DBIx::Data::Stream::Mapped->new({
22     inner => $self->_inner->to_stream,
23     mapper => sub { $inflator->inflate($_) }
24   });
25 }
26
27 sub clear { shift->_inner->clear }
28
29 sub get {
30   my ($self, $spec) = @_;
31   my $inflator = $self->_inflator;
32   $inflator->inflate(
33     $self->_inner->get(
34       $inflator->deflate_spec($spec)
35     )
36   );
37 }
38
39 sub replace {
40   my ($self, $spec, $body) = @_;
41   my $inflator = $self->_inflator;
42   $self->_inner->replace(
43     $inflator->deflate_spec($spec),
44     $inflator->deflate_body($body),
45   );
46 }
47
48 sub add {
49   my ($self, $body) = @_;
50   my $inflator = $self->_inflator;
51   $inflator->inflate(
52     $self->_inner->add(
53       $inflator->deflate_body($body)
54     )
55   );
56 }
57
58 sub remove {
59   my ($self, $spec) = @_;
60   $self->_inner->remove($self->_inflator->deflate_spec($spec));
61 }
62
63 1;