File Coverage

blib/lib/PPI/Element.pm
Criterion Covered Total %
statement 173 194 89.1
branch 62 92 67.3
condition 9 15 60.0
subroutine 53 58 91.3
pod 26 26 100.0
total 323 385 83.9


line stmt bran cond sub pod time code
1             package PPI::Element;
2              
3             =pod
4              
5             =head1 NAME
6              
7             PPI::Element - The abstract Element class, a base for all source objects
8              
9             =head1 INHERITANCE
10              
11             PPI::Element is the root of the PDOM tree
12              
13             =head1 DESCRIPTION
14              
15             The abstract C serves as a base class for all source-related
16             objects, from a single whitespace token to an entire document. It provides
17             a basic set of methods to provide a common interface and basic
18             implementations.
19              
20             =head1 METHODS
21              
22             =cut
23              
24 64     64   336 use strict;
  64         106  
  64         1730  
25 64     64   20599 use Clone 0.30 ();
  64         128362  
  64         1535  
26 64     64   410 use Scalar::Util qw{refaddr};
  64         102  
  64         2530  
27 64     64   297 use Params::Util qw{_INSTANCE _ARRAY};
  64         106  
  64         2076  
28 64     64   356 use List::Util ();
  64         86  
  64         707  
29 64     64   546 use PPI::Util ();
  64         91  
  64         728  
30 64     64   25490 use PPI::Node ();
  64         159  
  64         1581  
31 64     64   369 use PPI::Singletons '%_PARENT';
  64         103  
  64         5739  
32              
33             our $VERSION = '1.275';
34              
35             our $errstr = "";
36              
37 64     64   343 use overload 'bool' => \&PPI::Util::TRUE;
  64         101  
  64         348  
38 64     64   3336 use overload '""' => 'content';
  64         98  
  64         173  
39 64     64   2901 use overload '==' => '__equals';
  64         102  
  64         161  
40 64     64   2712 use overload '!=' => '__nequals';
  64         120  
  64         160  
41 64     64   2644 use overload 'eq' => '__eq';
  64         98  
  64         172  
42 64     64   2776 use overload 'ne' => '__ne';
  64         152  
  64         232  
43              
44              
45              
46              
47              
48             #####################################################################
49             # General Properties
50              
51             =pod
52              
53             =head2 significant
54              
55             Because we treat whitespace and other non-code items as Tokens (in order to
56             be able to "round trip" the L back to a file) the
57             C method allows us to distinguish between tokens that form a
58             part of the code, and tokens that aren't significant, such as whitespace,
59             POD, or the portion of a file after (and including) the C<__END__> token.
60              
61             Returns true if the Element is significant, or false it not.
62              
63             =cut
64              
65             ### XS -> PPI/XS.xs:_PPI_Element__significant 0.845+
66             sub significant() { 1 }
67              
68             =pod
69              
70             =head2 class
71              
72             The C method is provided as a convenience, and really does nothing
73             more than returning C. However, some people have found that
74             they appreciate the laziness of C<$Foo-Eclass eq 'whatever'>, so I
75             have caved to popular demand and included it.
76              
77             Returns the class of the Element as a string
78              
79             =cut
80              
81 0     0 1 0 sub class { ref($_[0]) }
82              
83             =pod
84              
85             =head2 tokens
86              
87             The C method returns a list of L objects for the
88             Element, essentially getting back that part of the document as if it had
89             not been lexed.
90              
91             This also means there are no Statements and no Structures in the list,
92             just the Token classes.
93              
94             =cut
95              
96 288051     288051 1 423757 sub tokens { $_[0] }
97              
98             =pod
99              
100             =head2 content
101              
102             For B C, the C method will reconstitute the
103             base code for it as a single string. This method is also the method used
104             for overloading stringification. When an Element is used in a double-quoted
105             string for example, this is the method that is called.
106              
107             B
108              
109             You should be aware that because of the way that here-docs are handled, any
110             here-doc content is not included in C, and as such you should
111             B eval or execute the result if it contains any L.
112              
113             The L method C should be used to stringify a PDOM
114             document into something that can be executed as expected.
115              
116             Returns the basic code as a string (excluding here-doc content).
117              
118             =cut
119              
120             ### XS -> PPI/XS.xs:_PPI_Element__content 0.900+
121             sub content() { '' }
122              
123              
124              
125              
126              
127             #####################################################################
128             # Navigation Methods
129              
130             =pod
131              
132             =head2 parent
133              
134             Elements themselves are not intended to contain other Elements, that is
135             left to the L abstract class, a subclass of C.
136             However, all Elements can be contained B a parent Node.
137              
138             If an Element is within a parent Node, the C method returns the
139             Node.
140              
141             =cut
142              
143 2491     2491 1 12721 sub parent { $_PARENT{refaddr $_[0]} }
144              
145             =pod
146              
147             =head2 descendant_of $element
148              
149             Answers whether a C is contained within another one.
150              
151             Cs are considered to be descendants of themselves.
152              
153             =cut
154              
155             sub descendant_of {
156 6     6 1 1556 my $cursor = shift;
157 6 50       20 my $parent = shift or return undef;
158 6         21 while ( refaddr $cursor != refaddr $parent ) {
159 17 100       61 $cursor = $_PARENT{refaddr $cursor} or return '';
160             }
161 3         10 return 1;
162             }
163              
164             =pod
165              
166             =head2 ancestor_of $element
167              
168             Answers whether a C is contains another one.
169              
170             Cs are considered to be ancestors of themselves.
171              
172             =cut
173              
174             sub ancestor_of {
175 6     6 1 1547 my $self = shift;
176 6 50       22 my $cursor = shift or return undef;
177 6         20 while ( refaddr $cursor != refaddr $self ) {
178 17 100       57 $cursor = $_PARENT{refaddr $cursor} or return '';
179             }
180 3         11 return 1;
181             }
182              
183             =pod
184              
185             =head2 statement
186              
187             For a C that is contained (at some depth) within a
188             L, the C method will return the first parent
189             Statement object lexically 'above' the Element.
190              
191             Returns a L object, which may be the same Element if the
192             Element is itself a L object.
193              
194             Returns false if the Element is not within a Statement and is not itself
195             a Statement.
196              
197             =cut
198              
199             sub statement {
200 0     0 1 0 my $cursor = shift;
201 0         0 while ( ! _INSTANCE($cursor, 'PPI::Statement') ) {
202 0 0       0 $cursor = $_PARENT{refaddr $cursor} or return '';
203             }
204 0         0 $cursor;
205             }
206              
207             =pod
208              
209             =head2 top
210              
211             For a C that is contained within a PDOM tree, the C method
212             will return the top-level Node in the tree. Most of the time this should be
213             a L object, however this will not always be so. For example,
214             if a subroutine has been removed from its Document, to be moved to another
215             Document.
216              
217             Returns the top-most PDOM object, which may be the same Element, if it is
218             not within any parent PDOM object.
219              
220             =cut
221              
222             sub top {
223 193     193 1 267 my $cursor = shift;
224 193         907 while ( my $parent = $_PARENT{refaddr $cursor} ) {
225 392         1063 $cursor = $parent;
226             }
227 193         332 $cursor;
228             }
229              
230             =pod
231              
232             =head2 document
233              
234             For an Element that is contained within a L object,
235             the C method will return the top-level Document for the Element.
236              
237             Returns the L for this Element, or false if the Element is not
238             contained within a Document.
239              
240             =cut
241              
242             sub document {
243 181     181 1 401 my $top = shift->top;
244 181 50       1614 _INSTANCE($top, 'PPI::Document') and $top;
245             }
246              
247             =pod
248              
249             =head2 next_sibling
250              
251             All L objects (specifically, our parent Node) contain a number of
252             C objects. The C method returns the C
253             immediately after the current one, or false if there is no next sibling.
254              
255             =cut
256              
257             sub next_sibling {
258 83     83 1 91 my $self = shift;
259 83 100       243 my $parent = $_PARENT{refaddr $self} or return '';
260 78         109 my $key = refaddr $self;
261 78         110 my $elements = $parent->{children};
262             my $position = List::Util::first {
263 270     270   355 refaddr $elements->[$_] == $key
264 78         239 } 0..$#$elements;
265 78 100       296 $elements->[$position + 1] || '';
266             }
267              
268             =pod
269              
270             =head2 snext_sibling
271              
272             As per the other 's' methods, the C method returns the next
273             B sibling of the C object.
274              
275             Returns a C object, or false if there is no 'next' significant
276             sibling.
277              
278             =cut
279              
280             sub snext_sibling {
281 2223     2223 1 6668 my $self = shift;
282 2223 100       7913 my $parent = $_PARENT{refaddr $self} or return '';
283 2216         2820 my $key = refaddr $self;
284 2216         2733 my $elements = $parent->{children};
285             my $position = List::Util::first {
286 11992     11992   14718 refaddr $elements->[$_] == $key
287 2216         8472 } 0..$#$elements;
288 2216         6663 while ( defined(my $it = $elements->[++$position]) ) {
289 2199 100       6551 return $it if $it->significant;
290             }
291 25         72 '';
292             }
293              
294             =pod
295              
296             =head2 previous_sibling
297              
298             All L objects (specifically, our parent Node) contain a number of
299             C objects. The C method returns the Element
300             immediately before the current one, or false if there is no 'previous'
301             C object.
302              
303             =cut
304              
305             sub previous_sibling {
306 76     76 1 83 my $self = shift;
307 76 100       204 my $parent = $_PARENT{refaddr $self} or return '';
308 72         94 my $key = refaddr $self;
309 72         91 my $elements = $parent->{children};
310             my $position = List::Util::first {
311 248     248   330 refaddr $elements->[$_] == $key
312 72         219 } 0..$#$elements;
313 72 100 66     339 $position and $elements->[$position - 1] or '';
314             }
315              
316             =pod
317              
318             =head2 sprevious_sibling
319              
320             As per the other 's' methods, the C method returns
321             the previous B sibling of the C object.
322              
323             Returns a C object, or false if there is no 'previous' significant
324             sibling.
325              
326             =cut
327              
328             sub sprevious_sibling {
329 1499     1499 1 2858 my $self = shift;
330 1499 100       4378 my $parent = $_PARENT{refaddr $self} or return '';
331 1498         1869 my $key = refaddr $self;
332 1498         1936 my $elements = $parent->{children};
333             my $position = List::Util::first {
334 9710     9710   11523 refaddr $elements->[$_] == $key
335 1498         5745 } 0..$#$elements;
336 1498   66     6414 while ( $position-- and defined(my $it = $elements->[$position]) ) {
337 1491 100       4524 return $it if $it->significant;
338             }
339 21         49 '';
340             }
341              
342             =pod
343              
344             =head2 first_token
345              
346             As a support method for higher-order algorithms that deal specifically with
347             tokens and actual Perl content, the C method finds the first
348             PPI::Token object within or equal to this one.
349              
350             That is, if called on a L subclass, it will descend until it
351             finds a L. If called on a L object, it will return
352             the same object.
353              
354             Returns a L object, or dies on error (which should be extremely
355             rare and only occur if an illegal empty L exists below the
356             current Element somewhere.)
357              
358             =cut
359              
360             sub first_token {
361 15     15 1 374 my $cursor = shift;
362 15         33 while ( $cursor->isa('PPI::Node') ) {
363 18 50       67 $cursor = $cursor->first_element
364             or die "Found empty PPI::Node while getting first token";
365             }
366 15         32 $cursor;
367             }
368              
369              
370             =pod
371              
372             =head2 last_token
373              
374             As a support method for higher-order algorithms that deal specifically with
375             tokens and actual Perl content, the C method finds the last
376             PPI::Token object within or equal to this one.
377              
378             That is, if called on a L subclass, it will descend until it
379             finds a L. If called on a L object, it will return
380             the itself.
381              
382             Returns a L object, or dies on error (which should be extremely
383             rare and only occur if an illegal empty L exists below the
384             current Element somewhere.)
385              
386             =cut
387              
388             sub last_token {
389 14     14 1 34 my $cursor = shift;
390 14         29 while ( $cursor->isa('PPI::Node') ) {
391 18 50       55 $cursor = $cursor->last_element
392             or die "Found empty PPI::Node while getting first token";
393             }
394 14         27 $cursor;
395             }
396              
397             =pod
398              
399             =head2 next_token
400              
401             As a support method for higher-order algorithms that deal specifically with
402             tokens and actual Perl content, the C method finds the
403             L object that is immediately after the current Element, even if
404             it is not within the same parent L as the one for which the
405             method is being called.
406              
407             Note that this is B defined as a L-specific method,
408             because it can be useful to find the next token that is after, say, a
409             L, although obviously it would be useless to want the
410             next token after a L.
411              
412             Returns a L object, or false if there are no more tokens after
413             the Element.
414              
415             =cut
416              
417             sub next_token {
418 61     61 1 443 my $cursor = shift;
419              
420             # Find the next element, going upwards as needed
421 61         62 while ( 1 ) {
422 74         136 my $element = $cursor->next_sibling;
423 74 100       136 if ( $element ) {
424 52 100       151 return $element if $element->isa('PPI::Token');
425 10         38 return $element->first_token;
426             }
427 22 100       51 $cursor = $cursor->parent or return '';
428 18 100 66     68 if ( $cursor->isa('PPI::Structure') and $cursor->finish ) {
429 5         22 return $cursor->finish;
430             }
431             }
432             }
433              
434             =pod
435              
436             =head2 previous_token
437              
438             As a support method for higher-order algorithms that deal specifically with
439             tokens and actual Perl content, the C method finds the
440             L object that is immediately before the current Element, even
441             if it is not within the same parent L as this one.
442              
443             Note that this is not defined as a L-only method, because it can
444             be useful to find the token is before, say, a L, although
445             obviously it would be useless to want the next token before a
446             L.
447              
448             Returns a L object, or false if there are no more tokens before
449             the C.
450              
451             =cut
452              
453             sub previous_token {
454 59     59 1 405 my $cursor = shift;
455              
456             # Find the previous element, going upwards as needed
457 59         59 while ( 1 ) {
458 70         110 my $element = $cursor->previous_sibling;
459 70 100       139 if ( $element ) {
460 51 100       139 return $element if $element->isa('PPI::Token');
461 9         30 return $element->last_token;
462             }
463 19 100       31 $cursor = $cursor->parent or return '';
464 16 100 66     51 if ( $cursor->isa('PPI::Structure') and $cursor->start ) {
465 5         9 return $cursor->start;
466             }
467             }
468             }
469              
470              
471              
472              
473              
474             #####################################################################
475             # Manipulation
476              
477             =pod
478              
479             =head2 clone
480              
481             As per the L module, the C method makes a perfect copy of
482             an Element object. In the generic case, the implementation is done using
483             the L module's mechanism itself. In higher-order cases, such as for
484             Nodes, there is more work involved to keep the parent-child links intact.
485              
486             =cut
487              
488             sub clone {
489 6     6 1 251 Clone::clone(shift);
490             }
491              
492             =pod
493              
494             =head2 insert_before @Elements
495              
496             The C method allows you to insert lexical perl content, in
497             the form of C objects, before the calling C. You
498             need to be very careful when modifying perl code, as it's easy to break
499             things.
500              
501             In its initial incarnation, this method allows you to insert a single
502             Element, and will perform some basic checking to prevent you inserting
503             something that would be structurally wrong (in PDOM terms).
504              
505             In future, this method may be enhanced to allow the insertion of multiple
506             Elements, inline-parsed code strings or L objects.
507              
508             Returns true if the Element was inserted, false if it can not be inserted,
509             or C if you do not provide a C object as a parameter.
510              
511             =cut
512              
513             sub __insert_before {
514 2     2   5 my $self = shift;
515 2         6 $self->parent->__insert_before_child( $self, @_ );
516             }
517              
518             =pod
519              
520             =head2 insert_after @Elements
521              
522             The C method allows you to insert lexical perl content, in
523             the form of C objects, after the calling C. You need
524             to be very careful when modifying perl code, as it's easy to break things.
525              
526             In its initial incarnation, this method allows you to insert a single
527             Element, and will perform some basic checking to prevent you inserting
528             something that would be structurally wrong (in PDOM terms).
529              
530             In future, this method may be enhanced to allow the insertion of multiple
531             Elements, inline-parsed code strings or L objects.
532              
533             Returns true if the Element was inserted, false if it can not be inserted,
534             or C if you do not provide a C object as a parameter.
535              
536             =cut
537              
538             sub __insert_after {
539 2     2   4 my $self = shift;
540 2         7 $self->parent->__insert_after_child( $self, @_ );
541             }
542              
543             =pod
544              
545             =head2 remove
546              
547             For a given C, the C method will remove it from its
548             parent B, along with all of its children.
549              
550             Returns the C itself as a convenience, or C if an error
551             occurs while trying to remove the C.
552              
553             =cut
554              
555             sub remove {
556 64     64 1 75 my $self = shift;
557 64 50       111 my $parent = $self->parent or return $self;
558 64         191 $parent->remove_child( $self );
559             }
560              
561             =pod
562              
563             =head2 delete
564              
565             For a given C, the C method will remove it from its
566             parent, immediately deleting the C and all of its children (if it
567             has any).
568              
569             Returns true if the C was successfully deleted, or C if
570             an error occurs while trying to remove the C.
571              
572             =cut
573              
574             sub delete {
575 64 50   64 1 128 $_[0]->remove or return undef;
576 64         196 $_[0]->DESTROY;
577 64         119 1;
578             }
579              
580             =pod
581              
582             =head2 replace $Element
583              
584             Although some higher level class support more exotic forms of replace,
585             at the basic level the C method takes a single C as
586             an argument and replaces the current C with it.
587              
588             To prevent accidental damage to code, in this initial implementation the
589             replacement element B be of the same class (or a subclass) as the
590             one being replaced.
591              
592             =cut
593              
594             sub replace {
595 0 0   0 1 0 my $self = ref $_[0] ? shift : return undef;
596 0 0       0 _INSTANCE(shift, ref $self) or return undef;
597 0         0 die "The ->replace method has not yet been implemented";
598             }
599              
600             =pod
601              
602             =head2 location
603              
604             If the Element exists within a L that has
605             indexed the Element locations using C, the
606             C method will return the location of the first character of the
607             Element within the Document.
608              
609             Returns the location as a reference to a five-element array in the form C<[
610             $line, $rowchar, $col, $logical_line, $logical_file_name ]>. The values are in
611             a human format, with the first character of the file located at C<[ 1, 1, 1, ?,
612             'something' ]>.
613              
614             The second and third numbers are similar, except that the second is the
615             literal horizontal character, and the third is the visual column, taking
616             into account tabbing (see L).
617              
618             The fourth number is the line number, taking into account any C<#line>
619             directives. The fifth element is the name of the file that the element was
620             found in, if available, taking into account any C<#line> directives.
621              
622             Returns C on error, or if the L object has not been
623             indexed.
624              
625             =cut
626              
627             sub location {
628 78587     78587 1 481112 my $self = shift;
629              
630 78587 50       86800 $self->_ensure_location_present or return undef;
631              
632             # Return a copy, not the original
633 78587         73311 return [ @{$self->{_location}} ];
  78587         178314  
634             }
635              
636             =pod
637              
638             =head2 line_number
639              
640             If the Element exists within a L that has indexed the Element
641             locations using C, the C method
642             will return the line number of the first character of the Element within the
643             Document.
644              
645             Returns C on error, or if the L object has not been
646             indexed.
647              
648             =cut
649              
650             sub line_number {
651 94     94 1 9913 my $self = shift;
652              
653 94 50       170 my $location = $self->location() or return undef;
654 94         198 return $location->[0];
655             }
656              
657             =pod
658              
659             =head2 column_number
660              
661             If the Element exists within a L that has indexed the Element
662             locations using C, the C method
663             will return the column number of the first character of the Element within the
664             Document.
665              
666             Returns C on error, or if the L object has not been
667             indexed.
668              
669             =cut
670              
671             sub column_number {
672 1     1 1 544 my $self = shift;
673              
674 1 50       5 my $location = $self->location() or return undef;
675 1         4 return $location->[1];
676             }
677              
678             =pod
679              
680             =head2 visual_column_number
681              
682             If the Element exists within a L that has indexed the Element
683             locations using C, the C
684             method will return the visual column number of the first character of the
685             Element within the Document, according to the value of
686             L.
687              
688             Returns C on error, or if the L object has not been
689             indexed.
690              
691             =cut
692              
693             sub visual_column_number {
694 1     1 1 544 my $self = shift;
695              
696 1 50       4 my $location = $self->location() or return undef;
697 1         4 return $location->[2];
698             }
699              
700             =pod
701              
702             =head2 logical_line_number
703              
704             If the Element exists within a L that has indexed the Element
705             locations using C, the C
706             method will return the line number of the first character of the Element within
707             the Document, taking into account any C<#line> directives.
708              
709             Returns C on error, or if the L object has not been
710             indexed.
711              
712             =cut
713              
714             sub logical_line_number {
715 1     1 1 569 my $self = shift;
716              
717 1         3 return $self->location()->[3];
718             }
719              
720             =pod
721              
722             =head2 logical_filename
723              
724             If the Element exists within a L that has indexed the Element
725             locations using C, the C
726             method will return the logical file name containing the first character of the
727             Element within the Document, taking into account any C<#line> directives.
728              
729             Returns C on error, or if the L object has not been
730             indexed.
731              
732             =cut
733              
734             sub logical_filename {
735 11     11 1 3433 my $self = shift;
736              
737 11 50       26 my $location = $self->location() or return undef;
738 11         61 return $location->[4];
739             }
740              
741             sub _ensure_location_present {
742 78587     78587   76442 my $self = shift;
743              
744 78587 100       110145 unless ( exists $self->{_location} ) {
745             # Are we inside a normal document?
746 173 50       501 my $Document = $self->document or return undef;
747 173 50       1368 if ( $Document->isa('PPI::Document::Fragment') ) {
748             # Because they can't be serialized, document fragments
749             # do not support the concept of location.
750 0         0 return undef;
751             }
752              
753             # Generate the locations. If they need one location, then
754             # the chances are they'll want more, and it's better that
755             # everything is already pre-generated.
756 173 50       555 $Document->index_locations or return undef;
757 173 50       546 unless ( exists $self->{_location} ) {
758             # erm... something went very wrong here
759 0         0 return undef;
760             }
761             }
762              
763 78587         102569 return 1;
764             }
765              
766             # Although flush_locations is only publically a Document-level method,
767             # we are able to implement it at an Element level, allowing us to
768             # selectively flush only the part of the document that occurs after the
769             # element for which the flush is called.
770             sub _flush_locations {
771 1     1   2 my $self = shift;
772 1 50       7 unless ( $self == $self->top ) {
773 0         0 return $self->top->_flush_locations( $self );
774             }
775              
776             # Get the full list of all Tokens
777 1         6 my @Tokens = $self->tokens;
778              
779             # Optionally allow starting from an arbitrary element (or rather,
780             # the first Token equal-to-or-within an arbitrary element)
781 1 50       7 if ( _INSTANCE($_[0], 'PPI::Element') ) {
782 0         0 my $start = shift->first_token;
783 0         0 while ( my $Token = shift @Tokens ) {
784 0 0       0 return 1 unless $Token->{_location};
785 0 0       0 next unless refaddr($Token) == refaddr($start);
786              
787             # Found the start. Flush its location
788 0         0 delete $$Token->{_location};
789 0         0 last;
790             }
791             }
792              
793             # Iterate over any remaining Tokens and flush their location
794 1         2 foreach my $Token ( @Tokens ) {
795 169         205 delete $Token->{_location};
796             }
797              
798 1         8 1;
799             }
800              
801              
802              
803              
804              
805             #####################################################################
806             # XML Compatibility Methods
807              
808             sub _xml_name {
809 5   33 5   29 my $class = ref $_[0] || $_[0];
810 5         25 my $name = lc join( '_', split /::/, $class );
811 5         26 substr($name, 4);
812             }
813              
814             sub _xml_attr {
815 5     5   20 return {};
816             }
817              
818             sub _xml_content {
819 5 100   5   28 defined $_[0]->{content} ? $_[0]->{content} : '';
820             }
821              
822              
823              
824              
825              
826             #####################################################################
827             # Internals
828              
829             # Set the error string
830             sub _error {
831 0     0   0 $errstr = $_[1];
832 0         0 undef;
833             }
834              
835             # Clear the error string
836             sub _clear {
837 0     0   0 $errstr = '';
838 0         0 $_[0];
839             }
840              
841             # Being DESTROYed in this manner, rather than by an explicit
842             # ->delete means our reference count has probably fallen to zero.
843             # Therefore we don't need to remove ourselves from our parent,
844             # just the index ( just in case ).
845             ### XS -> PPI/XS.xs:_PPI_Element__DESTROY 0.900+
846 363042     363042   1047651 sub DESTROY { delete $_PARENT{refaddr $_[0]} }
847              
848             # Operator overloads
849 732 50   732   2905 sub __equals { ref $_[1] and refaddr($_[0]) == refaddr($_[1]) }
850 1     1   5 sub __nequals { !__equals(@_) }
851             sub __eq {
852 6302 50   6302   1580903 my $self = _INSTANCE($_[0], 'PPI::Element') ? $_[0]->content : $_[0];
853 6302 100       15584 my $other = _INSTANCE($_[1], 'PPI::Element') ? $_[1]->content : $_[1];
854 6302         70942 $self eq $other;
855             }
856 1     1   6 sub __ne { !__eq(@_) }
857              
858             1;
859              
860             =pod
861              
862             =head1 TO DO
863              
864             It would be nice if C could be used in an ad-hoc manner. That is,
865             if called on an Element within a Document that has not been indexed, it will
866             do a one-off calculation to find the location. It might be very painful if
867             someone started using it a lot, without remembering to index the document,
868             but it would be handy for things that are only likely to use it once, such
869             as error handlers.
870              
871             =head1 SUPPORT
872              
873             See the L in the main module.
874              
875             =head1 AUTHOR
876              
877             Adam Kennedy Eadamk@cpan.orgE
878              
879             =head1 COPYRIGHT
880              
881             Copyright 2001 - 2011 Adam Kennedy.
882              
883             This program is free software; you can redistribute
884             it and/or modify it under the same terms as Perl itself.
885              
886             The full text of the license can be found in the
887             LICENSE file included with this module.
888              
889             =cut