AI-Ollama-Client

 view release on metacpan or  search on metacpan

xt/copyright.t  view on Meta::CPAN

#!perl
use warnings;
use strict;
use File::Find;
use Test::More tests => 1;
use POSIX 'strftime';

my $this_year = strftime '%Y', localtime;

my $last_modified_year = 0;

my $is_checkout = -d '.git';

require './Makefile.PL';
# Loaded from Makefile.PL
our %module = get_module_info();

my @files;
#my $blib = File::Spec->catfile(qw(blib lib));
find(\&wanted, grep { -d } ('lib'));

if( my $exe = $module{EXE_FILES}) {
    push @files, @$exe;
};

sub wanted {
  push @files, $File::Find::name if /\.p(l|m|od)$/;
}

sub collect {
    my( $file ) = @_;
    note $file;
    my $modified_ts;
    if( $is_checkout ) {
        # diag `git log -1 --pretty="format:%ct" "$file"`;
        $modified_ts = `git log -1 --pretty="format:%ct" "$file"`;
    } else {
        $modified_ts = (stat($_))[9];
    }

    my $modified_year;
    if( $modified_ts ) {
        $modified_year = strftime('%Y', localtime($modified_ts));
    } else {
        $modified_year = 1970;
    };

    open my $fh, '<', $file
        or die "Couldn't read $file: $!";
    my @copyright = map {
                        /\bcopyright\b.*?\d{4}-(\d{4})\b/i
                        ? [ $_ => $1 ]
                        : ()
                    }
                    <$fh>;
    my $copyright = 0;
    for (@copyright) {
        $copyright = $_->[1] > $copyright ? $_->[1] : $copyright;
    };

    return {
        file => $file,
        copyright_lines => \@copyright,
        copyright => $copyright,
        modified => $modified_year,



( run in 0.762 second using v1.01-cache-2.11-cpan-39bf76dae61 )