File Coverage

blib/lib/LaTeX/TikZ/Set/Polyline.pm
Criterion Covered Total %
statement 25 27 92.5
branch n/a
condition n/a
subroutine 9 10 90.0
pod 1 3 33.3
total 35 40 87.5


line stmt bran cond sub pod time code
1             package LaTeX::TikZ::Set::Polyline;
2              
3 10     10   31 use strict;
  10         12  
  10         246  
4 10     10   31 use warnings;
  10         13  
  10         285  
5              
6             =head1 NAME
7              
8             LaTeX::TikZ::Set::Polyline - A set object representing a possibly closed path composed of contiguous lines.
9              
10             =head1 VERSION
11              
12             Version 0.03
13              
14             =cut
15              
16             our $VERSION = '0.03';
17              
18 10     10   31 use LaTeX::TikZ::Set::Point;
  10         12  
  10         115  
19              
20 10     10   26 use LaTeX::TikZ::Interface;
  10         11  
  10         120  
21 10     10   27 use LaTeX::TikZ::Functor;
  10         10  
  10         140  
22              
23 10     10   27 use Mouse;
  10         18  
  10         35  
24 10     10   2135 use Mouse::Util::TypeConstraints;
  10         16  
  10         39  
25              
26             =head1 RELATIONSHIPS
27              
28             This class is a subclass of L, and as such inherits its C method.
29              
30             =cut
31              
32             extends 'LaTeX::TikZ::Set::Chain';
33              
34             subtype 'LaTeX::TikZ::Set::Polyline::Vertices'
35             => as 'ArrayRef[LaTeX::TikZ::Set::Point]'
36             => where { @$_ >= 2 }
37             => message { 'at least two LaTeX::TikZ::Set::Point objects are needed in order to build a polyline' };
38              
39             coerce 'LaTeX::TikZ::Set::Polyline::Vertices'
40             => from 'ArrayRef[Any]'
41             => via { [ map LaTeX::TikZ::Set::Point->new(point => $_), @$_ ] };
42              
43             =head1 ATTRIBUTES
44              
45             =head2 C
46              
47             The list of L objects (or scalars that coerce into such objects) that make the successive vertices of the path.
48              
49             =cut
50              
51             has '+_kids' => (
52             is => 'ro',
53             isa => 'LaTeX::TikZ::Set::Polyline::Vertices',
54             init_arg => 'points',
55             required => 1,
56             coerce => 1,
57             );
58              
59             =head2 C
60              
61             A boolean that indicates whether the polyline is closed or not.
62              
63             =cut
64              
65             has 'closed' => (
66             is => 'ro',
67             isa => 'Bool',
68             required => 1,
69             default => 0,
70             );
71              
72 0     0 1 0 sub points { @{$_[0]->_kids} }
  0         0  
73              
74             around 'BUILDARGS' => sub {
75             my ($orig, $class, %args) = @_;
76              
77             delete $args{cycle};
78              
79             $class->$orig(
80             %args,
81             connector => '--',
82             cycle => $args{closed},
83             );
84             };
85              
86             LaTeX::TikZ::Interface->register(
87             polyline => sub {
88 5     5 0 3649 shift;
89              
90 5         34 __PACKAGE__->new(
91             points => \@_,
92             closed => 0,
93             );
94             },
95             closed_polyline => sub {
96 6     6 0 5006 shift;
97              
98 6         41 __PACKAGE__->new(
99             points => \@_,
100             closed => 1,
101             );
102             },
103             );
104              
105             LaTeX::TikZ::Functor->default_rule(
106             (__PACKAGE__) => sub {
107             my ($functor, $set, @args) = @_;
108             $set->new(
109             points => [ map $_->$functor(@args), $set->kids ],
110             closed => $set->closed,
111             );
112             }
113             );
114              
115             __PACKAGE__->meta->make_immutable;
116              
117             =head1 SEE ALSO
118              
119             L, L.
120              
121             =head1 AUTHOR
122              
123             Vincent Pit, C<< >>, L.
124              
125             You can contact me by mail or on C (vincent).
126              
127             =head1 BUGS
128              
129             Please report any bugs or feature requests to C, or through the web interface at L.
130             I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
131              
132             =head1 SUPPORT
133              
134             You can find documentation for this module with the perldoc command.
135              
136             perldoc LaTeX::TikZ
137              
138             =head1 COPYRIGHT & LICENSE
139              
140             Copyright 2010,2011,2012,2013,2014,2015 Vincent Pit, all rights reserved.
141              
142             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
143              
144             =cut
145              
146             1; # End of LaTeX::TikZ::Set::Polyline