introduce ZConfig system, first cut at HTML::Zoom itself
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / SubObject.pm
diff --git a/lib/HTML/Zoom/SubObject.pm b/lib/HTML/Zoom/SubObject.pm
new file mode 100644 (file)
index 0000000..3620e26
--- /dev/null
@@ -0,0 +1,27 @@
+package HTML::Zoom::SubObject;
+
+use strict;
+use warnings FATAL => 'all';
+use Scalar::Util ();
+
+sub new {
+  my ($class, $args) = @_;
+  ($args||={})->{zconfig} ||= do {
+    require HTML::Zoom::ZConfig;
+    HTML::Zoom::ZConfig->new
+  };
+  my $new = { _zconfig => $args->{zconfig} };
+  Scalar::Util::weaken($new->{_zconfig});
+  bless($new, $class)
+}
+
+sub _zconfig { shift->{_zconfig} }
+
+sub with_zconfig {
+  my ($self, $zconfig) = @_;
+  my $new = bless({ %$self, _zconfig => $zconfig }, ref($self));
+  Scalar::Util::weaken($new->{_zconfig});
+  $new
+}
+
+1;