This file is indexed.

/usr/share/perl5/Carp/Datum/Assert.pm is in libcarp-datum-perl 1:0.1.3-8.

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#
# $Id: Assert.pm,v 0.1 2001/03/31 10:04:36 ram Exp $
#
#  Copyright (c) 2000-2001, Christophe Dehaudt & Raphael Manfredi
#  
#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.
#
# HISTORY
# $Log: Assert.pm,v $
# Revision 0.1  2001/03/31 10:04:36  ram
# Baseline for first Alpha release.
#
# $EndLog$
#

use strict;

package Carp::Datum::Assert;

require Exporter;

use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);

@EXPORT_OK = qw(assert_expr stack_dump);

use Log::Agent;

#
# assert_expr
#
# Fetch corresponding assert expression by going back to the file where
# the failure occurred, and parsing it.  This is very rough.
#
# Arguments:
#   offset		amount of frames to skip
#
# Returns assertion expression if found, undef otherwise.
#
sub assert_expr {
	my ($offset) = @_;
	my ($package, $file, $line) = caller($offset);

	local *FILE;
	unless (open(FILE, $file)) {
		logerr "can't open $file to get assert expression: $!";
		return;
	}

	local $_;
	my $count = $line;

	while (<FILE>) {
		last unless --$count > 0;
	}

	if ($count) {
		logwarn "reached EOF in $file whilst looking for line #$line";
		close FILE;
		return;
	}

	unless (s/^\s*(?:DASSERT|DREQUIRE|DENSURE|VERIFY)\b//) {
		chomp;
		logwarn "expected assertion at line #$line in $file, got: $_";
		close FILE;
		return;
	}

	#
	# Ok, we found something... now perform heuristic parsing...
	#

	my $expr = $_;

	$expr =~ s/^\s+//;
	$expr =~ s/\s+$//;
	$expr =~ s/^\(\s*//;

	if ($expr =~ s/(?:\)\s*)?;\s*$//) {
		#
		# Expression seems to be all on one line, like in:
		#
		#   DASSERT($a == $b, "a equals b");
		#
		# We're only interested in the "$a == $b" part though.
		#

		$expr =~ s/^\s*(.*?)\s*,\s*['"].*/$1/;   #' for emacs coloring
		close FILE;
		return $expr;
	}

	#
	# Expression is not contained on one line.  Advance in the file until
	# we see a ";" ending a line.  Limit to the next 10 lines, or something
	# is probably wrong.
	#

	my $limit = 10;
	while ($limit-- > 0) {
		$_ = <FILE>;
		unless (defined $_) {
			logwarn "reached EOF in $file whilst building ".
				"assert text from line #$line";
			close FILE;
			return;
		}
		chomp;
		s/^\s+//;
		$expr .= " " . $_;
		last if /;\s*$/;
	}
	close FILE;

	logwarn "assertion in $file, line #$line too long, cutting parsing"
		if $limit < 0;

	#
	# Got something?  Same processing as above.
	#

	if ($expr =~ s/(?:\)\s*)?;\s*$//) {
		$expr =~ s/^\s*(.*?)\s*,\s*['"].*/$1/;    #' for emacs coloring
		return $expr;
	}
	
	logwarn "can't compute assertion text at $file, line #$line, guessing...";

	#
	# Limit to first 60 chars, then mark end with ...
	#

	$expr =~ s/^(.*?),\s*['"].*/$1/;              #' for emacs coloring
	$expr = substr($expr, 0, 60);
	$expr .= "...";

	return $expr;
}

#
# stack_dump
#
# Dump the stack, discarding the first $offset frames.
#
sub stack_dump {
	my ($offset) = @_;

	#
	# Let Carp do the hard work.
	#

	require Carp;
	local $Carp::CarpLevel = 0;

	my $message = Carp::longmess("dump");
	my @stack = split(/\n/, $message);
	splice(@stack, 0, $offset + 1);		# Also skip initial "dump error" line

	foreach my $l (@stack) { $l =~ s/^\s+// }

	return \@stack;
}

1;

=head1 NAME

Carp::Datum::Assert - Assertion expression extractor

=head1 SYNOPSIS

 # Not meant to be used by user code

=head1 DESCRIPTION

This module is used internally by C<Carp::Datum> to extract the expression
text of a failed assertion, directly from the file.

This extraction is done lexically, and the general guidelines, which
are documented in L<Carp::Datum::Strip>, apply here too.

=head1 AUTHORS

Christophe Dehaudt and Raphael Manfredi are the original authors.

Send bug reports, hints, tips, suggestions to Dave Hoover at <squirrel@cpan.org>.

=head1 SEE ALSO

Carp::Datum(3), Carp::Datum::Strip(3).

=cut