add basic inflation wrapper and simple inflator
[dbsrgits/DBIx-Data-Store.git] / lib / DBIx / Data / Collection / Set / Wrapper / Inflate.pm
CommitLineData
34b924ec 1package DBIx::Data::Collection::Set::Wrapper::Inflate;
2
3use strictures 1;
4
5sub new {
6 my $proto = shift;
7 bless({ %{$_[0]} }, ref($proto)||$proto);
8}
9
10sub _inflator { shift->{inflator} }
11sub _inner { shift->{inner} }
12
13sub flatten {
14 my ($self) = @_;
15 map $self->_inflator->inflate($_), $self->_inner->flatten;
16}
17
18sub 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
27sub clear { shift->_inner->clear }
28
29sub 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
39sub 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
48sub 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
58sub remove {
59 my ($self, $spec) = @_;
60 $self->_inner->remove($self->_inflator->deflate_spec($spec));
61}
62
631;