lib/CairoX/CuttingLine.pm

filter: Statementstmt 15.0% 8 / 53 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 20.0% 2 / 10 Podpod 0.0% 0 / 8 totaltotal 10.6% 10 / 94 CC 13 SCAR 30.6
CC
13
Cov
11%
stroke
56.0
cr
6.0
set
6.0
CRAP 21.3
↑ Summary
1 package CairoX::CuttingLine;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 CairoX::CuttingLine - draw cutting line to cairo surface
9  
10 =head1 VERSION
11  
12 Version 0.05
13  
14 =cut
15  
16 1 our $VERSION = '0.05';
17  
18  
19 =head1 SYNOPSIS
20  
21 to use CairoX::CuttingLine to render cutting lines to a canvas:
22  
23 use CairoX::CuttingLine;
24  
25 we need to provide L<Cairo::Context> for L<CairoX::CuttingLine> method new.
26  
27 my $surf = Cairo::ImageSurface->create ('argb32', 200 , 200 );
28 my $cr = Cairo::Context->create ($surf);
29  
30 set Cairo::Context object
31  
32 my $page = CairoX::CuttingLine->new( $cr );
33  
34 or by cr accessor
35  
36 $page->cr( $cr );
37  
38 $page->set( x => 10 , y => 10 );
39 $page->size( width => 100 , width => 120 );
40 $page->length( 10 );
41 $page->line_width( 3 );
42 $page->color( 1, 1, 1, 1 ); # for set_source_rgba
43 $page->stroke();
44  
45 =head1 DESCRIPTION
46  
47 CairoX::CuttingLine draws cutting line like this:
48  
49 | |
50 -+ +-
51 IMAGE
52 -+ +-
53 | |
54  
55 =head1 FUNCTIONS
56  
57 =cut
58  
59 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $class = shift;
61 0 my $self = {};
62 0 bless $self , $class;
63 0 $self->{cr} = shift;
64 0 return $self;
65 }
66  
67 0 ▶sub cr {
Subroutine cr: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my $self = shift;
69 0 ▶ $self->{cr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
70 0 $self->{cr};
71 }
72  
73 0 ▶sub set {
Subroutine set: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my $self = shift;
75 0 ▶ $self->{p} = { @_ } if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
76 0 return $self->{p};
77 }
78  
79 0 ▶sub length {
Subroutine length: not called CC=2 SCAR=17.9
Pod undocumented
80 0 my $self = shift;
81 0 ▶ $self->{length} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
82 0 $self->{length};
83 }
84  
85 0 ▶sub size {
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my $self = shift;
87 0 ▶ $self->{size} = { @_ } if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
88 0 $self->{size};
89 }
90  
91 0 ▶sub color {
Subroutine color: not called CC=2 SCAR=17.9
Pod undocumented
92 0 my $self = shift;
93 0 ▶ $self->{color} = [ @_ ] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
94 0 $self->{color};
95 }
96  
97 0 ▶sub line_width {
Subroutine line_width: not called CC=2 SCAR=17.9
Pod undocumented
98 0 my $self = shift;
99 0 ▶ $self->{line_width} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
100 0 $self->{line_width};
101 }
102  
103 0 ▶sub stroke {
Subroutine stroke: not called CC=7 SCAR=40.3
Pod undocumented
104 0 my $self = shift;
105 0 my $cr = $self->{cr};
106 0 $cr->save;
107  
108 0 my $color = $self->{color};
109 0 ▶ $color ||= [1,1,1,1];
Condition0%0/2
$color ||= [1, 1, 1, 1]
l!l
00
MC/DC0%0/1
$color ||= [1, 1, 1, 1]
$color
Truth table0%0/2
A
A= $color
Aresult
11
00
110  
111 0 $cr->set_source_rgba( @$color );
112 0 $cr->set_line_width( $self->line_width );
113 0 my $pos = $self->set;
114  
115 0 my $s = $self->size;
116 0 my $line_len = $self->length;
117  
118 0 for my $p ( 0 .. 3 ) {
119  
120 0 my ( $c_x, $c_y ) = ( $pos->{x}, $pos->{y} );
121 0 ▶ if( $p & 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p & 1) 0 0 0
122 0 $c_x += $s->{width};
123 }
124 0 ▶ if( $p & 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p & 2) 0 0 0
125 0 $c_y += $s->{height};
126 }
127  
128 0 $cr->move_to( $c_x , $c_y );
129 0 ▶ $cr->line_to(
Branch: 1 branch
BranchTrueFalseTotal
$p & 1 ? : 0 0 0
130 $c_x + ( $p & 1 ? $line_len : -$line_len ),
131 $c_y
132 );
133  
134 0 $cr->move_to( $c_x , $c_y );
135 0 ▶ $cr->line_to(
Branch: 1 branch
BranchTrueFalseTotal
$p & 2 ? : 0 0 0
136 $c_x,
137 $c_y + ( $p & 2 ? $line_len : -$line_len ),
138 );
139 0 $cr->stroke();
140 }
141 0 $cr->restore;
142 }
143  
144  
145  
146 =head1 AUTHOR
147  
148 Cornelius, C<< <cornelius.howl at gmail.com> >>
149  
150 =head1 BUGS
151  
152 Please report any bugs or feature requests to C<bug-cairo-cuttingline at rt.cpan.org>, or through
153 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cairo-CuttingLine>. I will be notified, and then you'll
154 automatically be notified of progress on your bug as I make changes.
155  
156 =head1 SUPPORT
157  
158 You can find documentation for this module with the perldoc command.
159  
160 perldoc CairoX::CuttingLine
161  
162  
163 You can also look for information at:
164  
165 =over 4
166  
167 =item * RT: CPAN's request tracker
168  
169 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Cairo-CuttingLine>
170  
171 =item * AnnoCPAN: Annotated CPAN documentation
172  
173 L<http://annocpan.org/dist/Cairo-CuttingLine>
174  
175 =item * CPAN Ratings
176  
177 L<http://cpanratings.perl.org/d/Cairo-CuttingLine>
178  
179 =item * Search CPAN
180  
181 L<http://search.cpan.org/dist/Cairo-CuttingLine/>
182  
183 =back
184  
185  
186 =head1 ACKNOWLEDGEMENTS
187  
188  
189 =head1 COPYRIGHT & LICENSE
190  
191 Copyright 2009 Cornelius, all rights reserved.
192  
193 This program is free software; you can redistribute it and/or modify it
194 under the same terms as Perl itself.
195  
196  
197 =cut
198  
199 1 1; # End of CairoX::CuttingLine
↑ Summary