]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Point.pm
Introduce LaTeX::TikZ::Functor
[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::Functor;
21
22 use Any::Moose;
23 use Any::Moose 'Util::TypeConstraints';
24
25 with 'LaTeX::TikZ::Set::Op';
26
27 has 'point' => (
28  is       => 'ro',
29  isa      => 'LaTeX::TikZ::Point::Autocoerce',
30  required => 1,
31  coerce   => 1,
32  handles  => [ qw/x y/ ],
33 );
34
35 coerce 'LaTeX::TikZ::Set::Point'
36     => from 'Any'
37     => via { __PACKAGE__->new(point => $_) };
38
39 coerce 'LaTeX::TikZ::Point::Autocoerce'
40     => from 'LaTeX::TikZ::Set::Point'
41     => via { $_->point };
42
43 sub path {
44  my ($set, $tikz) = @_;
45
46  my $p = $set->point;
47
48  '(' . $tikz->len($p->x) . ',' . $tikz->len($p->y) . ')';
49 }
50
51 use LaTeX::TikZ::Interface point => sub {
52  shift;
53
54  my $point = @_ == 0 ? 0
55                      : @_ == 1 ? $_[0]
56                                : \@_;
57  __PACKAGE__->new(point => $point);
58 };
59
60 LaTeX::TikZ::Functor->default_rule(
61  (__PACKAGE__) => sub {
62   my ($functor, $set, @args) = @_;
63   $set->new(point => $set->point);
64  }
65 );
66
67 __PACKAGE__->meta->make_immutable;
68
69 =head1 AUTHOR
70
71 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
72
73 You can contact me by mail or on C<irc.perl.org> (vincent).
74
75 =head1 BUGS
76
77 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>.
78 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
79
80 =head1 SUPPORT
81
82 You can find documentation for this module with the perldoc command.
83
84     perldoc LaTeX::TikZ
85
86 =head1 COPYRIGHT & LICENSE
87
88 Copyright 2010 Vincent Pit, all rights reserved.
89
90 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
91
92 =cut
93
94 1; # End of LaTeX::TikZ::Set::Point