return add args if no return from the insert_one query in CRUD so RETURNING isn't...
[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   if (my $got = $self->_inner->get($inflator->deflate_spec($spec))) {
33     return $inflator->inflate($got);
34   }
35   return undef;
36 }
37
38 sub 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
47 sub 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
57 sub remove {
58   my ($self, $spec) = @_;
59   $self->_inner->remove($self->_inflator->deflate_spec($spec));
60 }
61
62 sub map {
63   require DBIx::Data::Collection::Set::Mapped;
64   DBIx::Data::Collection::Set::Mapped->new({
65     inner => $_[0], mapper => $_[1]
66   });
67 }
68
69 1;