File Coverage

blib/lib/Devel/PerlySense/Document/Location.pm
Criterion Covered Total %
statement 48 48 100.0
branch n/a
condition 8 8 100.0
subroutine 14 14 100.0
pod 3 3 100.0
total 73 73 100.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Devel::PerlySense::Document::Location - A file name + cursor position
4              
5             =head1 SYNOPSIS
6              
7              
8              
9              
10             =head1 DESCRIPTION
11              
12             A location describes a cursor position (optional) in a file, and
13             optional properties.
14              
15             =cut
16              
17              
18              
19              
20              
21 68     68   573 use strict;
  68         83  
  68         1525  
22 68     68   204 use warnings;
  68         73  
  68         1297  
23 68     68   672 use utf8;
  68         106  
  68         263  
24              
25             package Devel::PerlySense::Document::Location;
26             $Devel::PerlySense::Document::Location::VERSION = '0.0217';
27              
28              
29              
30              
31 68     68   3145 use Spiffy -Base;
  68         3660  
  68         324  
32 68     68   37680 use Carp;
  68     68   82  
  68     68   957  
  68         194  
  68         67  
  68         1195  
  68         184  
  68         71  
  68         2629  
33 68     68   212 use Data::Dumper;
  68         71  
  68         2101  
34 68     68   713 use Storable "dclone";
  68         2193  
  68         2323  
35 68     68   624 use PPI;
  68         84863  
  68         943  
36 68     68   617 use File::Slurp;
  68         8557  
  68         16201  
37              
38              
39              
40              
41              
42             =head1 PROPERTIES
43              
44             =head2 file
45              
46             Default: ""
47              
48             =cut
49             field "file" => "";
50              
51              
52              
53             =head2 row
54              
55             The row (0..) of the location. The actual rows are 1.., 0 means N/A.
56              
57             Default: 0
58              
59             =cut
60             field "row";
61              
62              
63              
64              
65              
66             =head2 col
67              
68             The col (0..) of the location. The actual cols are 1.., 0 means N/A.
69              
70             Default: 0
71              
72             =cut
73             field "col";
74              
75              
76              
77              
78              
79             =head2 rhProperty
80              
81             Hash ref with (names: name of payload, keys: some payload).
82              
83             A generic container for whatever things may be attached to this
84             location, like POD text, a PPI::Node, a type string or whatever.
85              
86             Default: {}
87              
88             =cut
89             field "rhProperty" => {};
90              
91              
92              
93              
94              
95             =head1 API METHODS
96              
97             =head2 new(file => $file, row => $row, col => $col)
98              
99             Create new Location object.
100              
101             =cut
102             sub new(@) {
103 14889     14889 1 183473 my $pkg = shift;
104 14889         30534 my (%p) = @_;
105              
106 14889         21285 my $self = bless {}, $pkg;
107              
108 14889   100     213411 $self->file($p{file} || "");
109 14889   100     259410 $self->row($p{row} || 0);
110 14889   100     228162 $self->col($p{col} || 0);
111 14889   100     253311 $self->rhProperty($p{rhProperty} || {});
112              
113 14889         91957 return($self);
114             }
115              
116              
117              
118              
119              
120             =head2 clone()
121              
122             Return clone of this object.
123              
124             Die on errors.
125              
126             =cut
127 92     92 1 174 sub clone {
128 92         6572 return(dclone($self));
129             }
130              
131              
132              
133              
134              
135             =head2 rhInfo()
136              
137             Return a hash ref with the complete attributes of the class, i.e. both
138             the file and the properties in rhProperty.
139              
140             =cut
141 2     2 1 9 sub rhInfo {
142 2         33 my $rhInfo = dclone($self->rhProperty);
143 2         74 for my $field (qw/ file row col /) {
144 6         92 $rhInfo->{$field} = $self->$field;
145             }
146            
147 2         16 return($rhInfo);
148             }
149              
150              
151              
152              
153              
154             1;
155              
156              
157              
158              
159              
160             __END__
161              
162             =encoding utf8
163              
164             =head1 AUTHOR
165              
166             Johan Lindstrom, C<< <johanl@cpan.org> >>
167              
168             =head1 BUGS
169              
170             Please report any bugs or feature requests to
171             C<bug-devel-perlysense@rt.cpan.org>, or through the web interface at
172             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-PerlySense>.
173             I will be notified, and then you'll automatically be notified of progress on
174             your bug as I make changes.
175              
176             =head1 ACKNOWLEDGEMENTS
177              
178             =head1 COPYRIGHT & LICENSE
179              
180             Copyright 2005 Johan Lindstrom, All Rights Reserved.
181              
182             This program is free software; you can redistribute it and/or modify it
183             under the same terms as Perl itself.
184              
185             =cut