]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Point.pm
Remove magic LaTeX::TikZ::Interface->import
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Point.pm
1 package LaTeX::TikZ::Set::Point;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ::Set::Point - A set object representing a point.
9
10 =head1 VERSION
11
12 Version 0.01
13
14 =cut
15
16 our $VERSION = '0.01';
17
18 use LaTeX::TikZ::Point;
19
20 use LaTeX::TikZ::Interface;
21 use LaTeX::TikZ::Functor;
22
23 use Any::Moose;
24 use Any::Moose 'Util::TypeConstraints';
25
26 with 'LaTeX::TikZ::Set::Op';
27
28 has 'point' => (
29  is       => 'ro',
30  isa      => 'LaTeX::TikZ::Point::Autocoerce',
31  required => 1,
32  coerce   => 1,
33  handles  => [ qw/x y/ ],
34 );
35
36 coerce 'LaTeX::TikZ::Set::Point'
37     => from 'Any'
38     => via { __PACKAGE__->new(point => $_) };
39
40 coerce 'LaTeX::TikZ::Point::Autocoerce'
41     => from 'LaTeX::TikZ::Set::Point'
42     => via { $_->point };
43
44 sub path {
45  my ($set, $tikz) = @_;
46
47  my $p = $set->point;
48
49  '(' . $tikz->len($p->x) . ',' . $tikz->len($p->y) . ')';
50 }
51
52 LaTeX::TikZ::Interface->register(
53  point => sub {
54   shift;
55
56   my $point = @_ == 0 ? 0
57                       : @_ == 1 ? $_[0]
58                                 : \@_;
59   __PACKAGE__->new(point => $point);
60  },
61 );
62
63 LaTeX::TikZ::Functor->default_rule(
64  (__PACKAGE__) => sub {
65   my ($functor, $set, @args) = @_;
66   $set->new(point => $set->point);
67  }
68 );
69
70 __PACKAGE__->meta->make_immutable;
71
72 =head1 AUTHOR
73
74 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
75
76 You can contact me by mail or on C<irc.perl.org> (vincent).
77
78 =head1 BUGS
79
80 Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
81 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
82
83 =head1 SUPPORT
84
85 You can find documentation for this module with the perldoc command.
86
87     perldoc LaTeX::TikZ
88
89 =head1 COPYRIGHT & LICENSE
90
91 Copyright 2010 Vincent Pit, all rights reserved.
92
93 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
94
95 =cut
96
97 1; # End of LaTeX::TikZ::Set::Point