bugfixes, tweaks, map support
[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;
967a2b04 32 if (my $got = $self->_inner->get($inflator->deflate_spec($spec))) {
33 return $inflator->inflate($got);
34 }
35 return undef;
34b924ec 36}
37
38sub replace {
39 my ($self, $spec, $body) = @_;
40 my $inflator = $self->_inflator;
41 $self->_inner->replace(
42 $inflator->deflate_spec($spec),
43 $inflator->deflate_body($body),
44 );
45}
46
47sub add {
48 my ($self, $body) = @_;
49 my $inflator = $self->_inflator;
50 $inflator->inflate(
51 $self->_inner->add(
52 $inflator->deflate_body($body)
53 )
54 );
55}
56
57sub remove {
58 my ($self, $spec) = @_;
59 $self->_inner->remove($self->_inflator->deflate_spec($spec));
60}
61
967a2b04 62sub map {
63 require DBIx::Data::Collection::Set::Mapped;
64 DBIx::Data::Collection::Set::Mapped->new({
65 inner => $_[0], mapper => $_[1]
66 });
67}
68
34b924ec 691;