This file is indexed.

/usr/share/perl5/PPIx/EditorTools/ReturnObject.pm is in libppix-editortools-perl 0.18-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package PPIx::EditorTools::ReturnObject;

# ABSTRACT: Simple object to return values from PPIx::EditorTools

use 5.008;
use strict;
use warnings;
use Carp;

our $VERSION = '0.18';

=pod

=head1 NAME

PPIx::EditorTools::ReturnObject - Simple object to return values from PPIx::EditorTools

=head1 SYNOPSIS

  my $brace = PPIx::EditorTools::FindUnmatchedBrace->new->find(
        code => "package TestPackage;\nsub x { 1;\n"
      );
  my $location = $brace->element->location;
  my $ppi      = $brace->element->ppi;

=head1 DESCRIPTION

Retuning a simple C<PPI::Element> from many of the C<PPIx::EditorTools>
methods often results in the loss of the overall context for that element.
C<PPIx::EditorTools::ReturnObject> provides an object that can be passed
around which retains the overall context.

For example, in C<PPIx::EditorTools::FindUnmatchedBrace> if the unmatched
brace were returned by its C<PPI::Structure::Block> the containing
C<PPI::Document> is likely to go out of scope, thus the C<location>
method no longer returns a valid location (rather it returns undef).
Using the C<ReturnObject> preserves the C<PPI::Document> and the containing
context.

=head1 METHODS

=over 4

=item new()

Constructor which should be used by C<PPIx::EditorTools>. Accepts the following
named parameters:

=over 4

=item ppi

A C<PPI::Document> representing the (possibly modified) code.

=item code

A string representing the (possibly modified) code.

=item element

A C<PPI::Element> or a subclass thereof representing the interesting element.

=back

=item ppi

Accessor to retrieve the C<PPI::Document>. May create the C<PPI::Document>
from the $code string (lazily) if needed.

=item code

Accessor to retrieve the string representation of the code. May be retrieved
from the C<PPI::Document> via the serialize method (lazily) if needed.

=back

=cut

sub new {
	my $class = shift;
	return bless {@_}, ref($class) || $class;
}

sub element {
	my ($self) = @_;

	# If element is a code ref, run the code once then cache the
	# result
	if (    exists $self->{element}
		and ref( $self->{element} )
		and ref( $self->{element} ) eq 'CODE' )
	{
		$self->{element} = $self->{element}->(@_);
	}

	return $self->{element};
}

sub ppi {
	my ( $self, $doc ) = @_;

	# $self->{ppi} = $doc if $doc;    # TODO: and isa?

	return $self->{ppi} if $self->{ppi};

	if ( $self->{code} ) {
		my $code = $self->{code};
		$self->{ppi} = PPI::Document->new( \$code );
		return $self->{ppi};
	}

	return;
}

sub code {
	my ( $self, $doc ) = @_;

	# $self->{code} = $doc if $doc;

	return $self->{code} if $self->{code};

	if ( $self->{ppi} ) {
		$self->{code} = $self->{ppi}->serialize;
		return $self->{code};
	}

	return;
}

1;

__END__

=head1 SEE ALSO

C<PPIx::EditorTools>, L<App::EditorTools>, L<Padre>, and L<PPI>.

=cut

# Copyright 2008-2009 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.