add basic inflation wrapper and simple inflator
[dbsrgits/DBIx-Data-Store.git] / lib / DBIx / Data / Collection / Set / Wrapper / Inflate.pm
diff --git a/lib/DBIx/Data/Collection/Set/Wrapper/Inflate.pm b/lib/DBIx/Data/Collection/Set/Wrapper/Inflate.pm
new file mode 100644 (file)
index 0000000..0330181
--- /dev/null
@@ -0,0 +1,63 @@
+package DBIx::Data::Collection::Set::Wrapper::Inflate;
+
+use strictures 1;
+
+sub new {
+  my $proto = shift;
+  bless({ %{$_[0]} }, ref($proto)||$proto);
+}
+
+sub _inflator { shift->{inflator} }
+sub _inner { shift->{inner} }
+
+sub flatten {
+  my ($self) = @_;
+  map $self->_inflator->inflate($_), $self->_inner->flatten;
+}
+
+sub to_stream {
+  my ($self) = @_;
+  my $inflator = $self->_inflator;
+  DBIx::Data::Stream::Mapped->new({
+    inner => $self->_inner->to_stream,
+    mapper => sub { $inflator->inflate($_) }
+  });
+}
+
+sub clear { shift->_inner->clear }
+
+sub get {
+  my ($self, $spec) = @_;
+  my $inflator = $self->_inflator;
+  $inflator->inflate(
+    $self->_inner->get(
+      $inflator->deflate_spec($spec)
+    )
+  );
+}
+
+sub replace {
+  my ($self, $spec, $body) = @_;
+  my $inflator = $self->_inflator;
+  $self->_inner->replace(
+    $inflator->deflate_spec($spec),
+    $inflator->deflate_body($body),
+  );
+}
+
+sub add {
+  my ($self, $body) = @_;
+  my $inflator = $self->_inflator;
+  $inflator->inflate(
+    $self->_inner->add(
+      $inflator->deflate_body($body)
+    )
+  );
+}
+
+sub remove {
+  my ($self, $spec) = @_;
+  $self->_inner->remove($self->_inflator->deflate_spec($spec));
+}
+
+1;