App-Licensecheck
view release on metacpan or search on metacpan
lib/App/Licensecheck.pm view on Meta::CPAN
}
else {
die $log->fatalf( 'unknown error: %s', $e );
}
}
}
method parse_file
{
# TODO: stop reuse slots across files, and drop this hack
$content = undef;
$license = undef;
$copyrights = undef;
if ( $top_lines == 0 ) {
my $licensed = String::License->new(
string => $self->content_extracleaned,
naming => $naming,
);
$license = $licensed->as_text;
$copyrights = copyright( $self->content_cleaned );
}
else {
my $licensed = String::License->new(
string => $self->content_extracleaned,
naming => $naming,
);
$license = $licensed->as_text;
$copyrights = copyright_optimistic( $self->content_cleaned );
if ( $offset and not $copyrights and $license eq 'UNKNOWN' ) {
# TODO: stop reuse slots across files, and drop this hack
$tail_content = undef;
my $licensed = String::License->new(
string => $self->content_extracleaned,
naming => $naming,
);
$license = $licensed->as_text;
$copyrights = copyright_optimistic( $self->content_cleaned );
}
$fh->close;
}
return ( $license, $copyrights );
}
method content
{
if ( $top_lines == 0 ) {
return $content
if defined($content);
if ( not defined($encoding) ) {
$log->debugf( 'reading whole file %s as raw bytes', $path );
$content = $path->slurp_raw;
}
else {
my $id = $encoding->name;
$log->debugf( 'decoding whole file %s as %s', $path, $id );
$content = $path->slurp( { binmode => ":encoding($id)" } );
}
$log->trace("----- content -----\n$content----- end content -----")
if $log->is_trace;
}
elsif ( not defined($license) or not defined($copyrights) ) {
# TODO: distinguish header from full content
return $content
if defined($content);
$content = '';
if ( not defined($encoding) ) {
$log->debugf( 'reading part(s) of file %s as raw bytes', $path );
$fh = $path->openr_raw;
}
else {
my $id = $encoding->name;
$log->debugf( 'decoding part(s) of file %s as %s', $path, $id );
$fh = $path->openr(":encoding($id)");
}
while ( my $line = $fh->getline ) {
last if ( $fh->input_line_number > $top_lines );
$content .= $line;
}
$log->trace("----- header -----\n$content----- end header -----")
if $log->is_trace;
if ($end_bytes) {
my $position = $fh->tell; # see IO::Seekable
my $filesize = $path->stat->size;
if ( $position >= $filesize - $end_bytes ) { # header overlaps
if ( $position < $filesize ) {
$log->debugf(
'tail offset set to %s (end of header)',
$position
);
$offset = $position;
}
elsif ( $position = $filesize ) {
$log->debug('header end matches file size');
$offset = 0;
}
else {
$log->error('header end beyond file size');
$offset = 0;
}
}
elsif ( $position > 0 ) {
$offset = $filesize - $end_bytes;
$log->debugf(
'tail offset set to %s',
$offset
);
}
elsif ( $position < 0 ) {
$log->error('header end could not be resolved');
$offset = 0;
}
( run in 0.909 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )