This file is indexed.

/usr/share/perl5/Padre/SLOC.pm is in padre 1.00+dfsg-3.

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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
package Padre::SLOC;

# A basic Source Lines of Code counter/accumulator

use 5.008;
use strict;
use warnings;
use Params::Util ();
use Padre::MIME  ();

our $VERSION    = '1.00';
our $COMPATIBLE = '0.95';

# Differentiate content between different types
my %CONTENT = (
	'application/javascript' => 'code',
	'application/x-pasm'     => 'code',
	'application/x-perl'     => 'code',
	'application/x-perl6'    => 'code',
	'application/x-php'      => 'code',
	'application/x-ruby'     => 'code',
	'application/x-tcl'      => 'code',
	'text/x-actionscript'    => 'code',
	'text/x-adasrc'          => 'code',
	'text/x-cobol'           => 'code',
	'text/x-csrc'            => 'code',
	'text/x-haskell'         => 'code',
	'text/x-java'            => 'code',
	'text/x-pascal'          => 'code',
	'text/x-perlxs'          => 'code',
	'text/x-python'          => 'code',
);





######################################################################
# Constructor

sub new {
	my $class = shift;
	return bless {}, $class;
}





######################################################################
# Statistics Capture

sub add {
	my $self = shift;
	my $add  = shift;
	foreach my $key ( sort keys %$add ) {
		next unless $add->{$key};
		$self->{$key} ||= 0;
		$self->{$key} += $add->{$key};
	}
	return 1;
}

sub add_text {
	my $self = shift;
	my $text = shift;
	my $mime = shift;

	# Normalise newlines
	$$text =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;

	# Detect MIME if not provided
	$mime ||= Padre::MIME->detect(
		text => $$text,
	);

	# Get the line count for the file
	my $count = $self->count_mime( $text, $mime );

	# Add the line counts for the scalar
	$self->add($count);
}

sub add_file {
	my $self = shift;
	my $file = shift;
	unless ( Params::Util::_INSTANCE( $file, 'Padre::File' ) ) {
		require Padre::File::Local;
		$file = Padre::File::Local->new($file);
	}

	# Load the file
	my $text = $file->read;
	return unless defined $text;

	# Detect the MIME type
	my $type = Padre::MIME->detect(
		file => $file->filename,
		text => $text,
	) or return;

	# Hand off to the more generic method
	$self->add_text( \$text, Padre::MIME->find($type) );
}

sub add_document {
	my $self     = shift;
	my $document = shift;
	my $text     = $document->text_get or return;
	my $mime     = $document->mime or return;
	$self->add_text( \$text, $mime );
}

sub add_editor {
	my $self     = shift;
	my $editor   = shift;
	my $document = $editor->document or return;
	$self->add_document($document);
}





######################################################################
# Statistics Reporting

sub total_content {
	my $self  = shift;
	my $total = 0;
	foreach my $key ( sort keys %$self ) {
		my ( $lang, $type ) = split /\s+/, $key;
		if ( $type eq 'content' ) {
			$total += $self->{$key};
		}
	}
	return $total;
}

sub report_languages {
	my $self = shift;
	my %hash = ();
	foreach my $key ( sort keys %$self ) {
		my ( $lang, $type ) = split /\s+/, $key;
		$hash{$lang} ||= 0;
		$hash{$lang} += $self->{$key};
	}
	return \%hash;
}

sub report_types {
	my $self = shift;
	my %hash = ();
	foreach my $key ( sort keys %$self ) {
		my ( $lang, $type ) = split /\s+/, $key;
		$hash{$type} ||= 0;
		$hash{$type} += $self->{$key};
	}
	return \%hash;
}

sub smart_types {
	my $self = shift;
	my %hash = ();
	foreach my $key ( sort keys %$self ) {
		my ( $lang, $type ) = split /\s+/, $key;
		next unless $CONTENT{$lang};
		if ( $type eq 'content' ) {
			$type = $CONTENT{$lang};
		}
		$hash{$type} ||= 0;
		$hash{$type} += $self->{$key};
	}
	return \%hash;
}





######################################################################
# SLOC Counters

sub count_mime {
	my $self = shift;
	my $text = shift;
	my $mime = shift;

	# Dispatch to language-specific counting methods
	if ( $mime->type eq 'application/x-perl' ) {
		return $self->count_perl5( $text, $mime );
	}
	if ( $mime->type eq 'text/x-pod' ) {
		return $self->count_perl5( $text, $mime );
	}

	# Fall back to the generic counting methods
	if ( $mime->comment ) {
		return $self->count_commented( $text, $mime );
	} else {
		return $self->count_uncommented( $text, $mime );
	}
}

sub count_perl5 {
	my $self  = shift;
	my $text  = shift;
	my %count = (
		'text/x-pod comment'         => 0,
		'text/x-pod blank'           => 0,
		'application/x-perl content' => 0,
		'application/x-perl comment' => 0,
		'application/x-perl blank'   => 0,
	);

	my $content = 1;
	foreach my $line ( split /\n/, $$text, -1 ) {
		if ( $line !~ /\S/ ) {
			if ($content) {
				$count{'application/x-perl blank'}++;
			} else {
				$count{'text/x-pod blank'}++;
			}
		} elsif ( $line =~ /^=cut\s*/ ) {
			$count{'text/x-pod comment'}++;
			$content = 1;
		} elsif ($content) {
			if ( $line =~ /^=\w+/ ) {
				$count{'text/x-pod comment'}++;
				$content = 0;
			} elsif ( $line =~ /^\s*#/ ) {
				$count{'application/x-perl comment'}++;
			} else {
				$count{'application/x-perl content'}++;
			}
		} else {
			$count{'text/x-pod comment'}++;
		}
	}

	return \%count;
}

# Find SLOC information for languages which have comments
sub count_commented {
	my $self    = shift;
	my $text    = shift;
	my $mime    = shift;
	my $type    = $mime->type;
	my $comment = $mime->comment or return undef;
	my $matches = $comment->line_match;
	my %count   = (
		"$type content" => 0,
		"$type comment" => 0,
		"$type blank"   => 0,
	);

	foreach my $line ( split /\n/, $$text ) {
		if ( $line !~ /\S/ ) {
			$count{"$type blank"}++;
		} elsif ( $line =~ $matches ) {
			$count{"$type comment"}++;
		} else {
			$count{"$type content"}++;
		}
	}

	return \%count;
}

# Find SLOC information for languages which do not have comments
sub count_uncommented {
	my $self  = shift;
	my $text  = shift;
	my $mime  = shift;
	my $type  = $mime->type;
	my %count = (
		"$type content" => 0,
		"$type blank"   => 0,
	);

	foreach my $line ( split /\n/, $$text ) {
		if ( $line !~ /\S/ ) {
			$count{"$type blank"}++;
		} else {
			$count{"$type content"}++;
		}
	}

	return \%count;
}

1;

# Copyright 2008-2013 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.