]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Set/Point.pm
Remove magic LaTeX::TikZ::Interface->import
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Point.pm
index c4749fe66ab879f51aa426fc3b01b0201621950e..5bf292b10ca11bffccb4c1b26c90af74f803a5e2 100644 (file)
@@ -17,17 +17,30 @@ our $VERSION = '0.01';
 
 use LaTeX::TikZ::Point;
 
+use LaTeX::TikZ::Interface;
+use LaTeX::TikZ::Functor;
+
 use Any::Moose;
+use Any::Moose 'Util::TypeConstraints';
 
 with 'LaTeX::TikZ::Set::Op';
 
 has 'point' => (
  is       => 'ro',
does     => 'LaTeX::TikZ::Point::Autocoerce',
isa      => 'LaTeX::TikZ::Point::Autocoerce',
  required => 1,
  coerce   => 1,
+ handles  => [ qw/x y/ ],
 );
 
+coerce 'LaTeX::TikZ::Set::Point'
+    => from 'Any'
+    => via { __PACKAGE__->new(point => $_) };
+
+coerce 'LaTeX::TikZ::Point::Autocoerce'
+    => from 'LaTeX::TikZ::Set::Point'
+    => via { $_->point };
+
 sub path {
  my ($set, $tikz) = @_;
 
@@ -36,11 +49,23 @@ sub path {
  '(' . $tikz->len($p->x) . ',' . $tikz->len($p->y) . ')';
 }
 
-use LaTeX::TikZ::Interface point => sub {
- shift;
+LaTeX::TikZ::Interface->register(
+ point => sub {
+  shift;
 
- __PACKAGE__->new(point => @_ > 1 ? \@_ : $_[0] );
-};
+  my $point = @_ == 0 ? 0
+                      : @_ == 1 ? $_[0]
+                                : \@_;
+  __PACKAGE__->new(point => $point);
+ },
+);
+
+LaTeX::TikZ::Functor->default_rule(
+ (__PACKAGE__) => sub {
+  my ($functor, $set, @args) = @_;
+  $set->new(point => $set->point);
+ }
+);
 
 __PACKAGE__->meta->make_immutable;