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   557 use strict;
  68         75  
  68         1547  
22 68     68   199 use warnings;
  68         74  
  68         1312  
23 68     68   655 use utf8;
  68         86  
  68         265  
24              
25             package Devel::PerlySense::Document::Location;
26             $Devel::PerlySense::Document::Location::VERSION = '0.0218';
27              
28              
29              
30              
31 68     68   3202 use Spiffy -Base;
  68         3674  
  68         317  
32 68     68   37596 use Carp;
  68     68   83  
  68     68   960  
  68         186  
  68         69  
  68         1238  
  68         185  
  68         66  
  68         2636  
33 68     68   217 use Data::Dumper;
  68         70  
  68         2150  
34 68     68   719 use Storable "dclone";
  68         2154  
  68         2358  
35 68     68   695 use PPI;
  68         95914  
  68         997  
36 68     68   868 use File::Slurp;
  68         8589  
  68         16187  
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 187070 my $pkg = shift;
104 14889         31841 my (%p) = @_;
105              
106 14889         21501 my $self = bless {}, $pkg;
107              
108 14889   100     215751 $self->file($p{file} || "");
109 14889   100     265459 $self->row($p{row} || 0);
110 14889   100     232409 $self->col($p{col} || 0);
111 14889   100     256745 $self->rhProperty($p{rhProperty} || {});
112              
113 14889         96060 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 141 sub clone {
128 92         6594 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         31 my $rhInfo = dclone($self->rhProperty);
143 2         37 for my $field (qw/ file row col /) {
144 6         87 $rhInfo->{$field} = $self->$field;
145             }
146            
147 2         14 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