<commit_before>package Tangerine::hook::list;

use 5.010;
use strict;
use warnings;
use parent 'Tangerine::Hook';
use List::Util 1.33 qw(any);
use Tangerine::HookData;
use Tangerine::Occurence;
use Tangerine::Utils qw(stripquotelike $vre);

sub run {
    my ($self, $s) = @_;
    if ((any { $s->[0] eq $_ } qw(use no)) && scalar(@$s) > 2 &&
        (any { $s->[1] eq $_ }
            qw(aliased base mixin::with Mojo::Base ok parent superclass
               Test::Class::Most))) {
        my ($version) = $s->[2] =~ $vre;
        $version //= '';
        my $voffset = $version ? 3 : 2;
        my @args;
        if (scalar(@$s) > $voffset) {
            return if $s->[$voffset] eq ';';
            @args = @$s;
            @args = @args[($voffset) .. $#args];
            @args = stripquotelike(@args);
            @args = grep { !/^-norequire$/ } @args
                if any { $s->[1] eq $_ } qw/parent superclass/;
            @args = grep { !/^-(base|strict)$/ } @args
                if $s->[1] eq 'Mojo::Base';
        }
        @args = $args[0]
            if $args[0] && any { $s->[1] eq $_ } qw/aliased mixin::with Mojo::Base ok/;
        if ($s->[1] eq 'Test::Class::Most') {
            my $tcmparent;
            my @results;
            for my $arg (@args) {
                if ($tcmparent) {
                    if (any { $arg eq $_ } qw/attributes is_abstract/) {
                        undef $tcmparent;
                        next
                    }
                    push @results, $arg
                } else {
                    if ($arg eq 'parent') {
                        $tcmparent++;
                        undef @results
                    }
                }
            }
            @args = @results
        }
        my %found;
        for (my $i = 0; $i < scalar(@args); $i++) {
            $found{$args[$i]} = '';
            if ($args[$i+1] && $args[$i+1] =~ /^v?\d+(?:\.\d+)*$/) {
                $found{$args[$i]} = $args[$i+1];
                $i++
            }
        }
        return Tangerine::HookData->new(
            modules => {
                map {
                    ( $_ => Tangerine::Occurence->new(version => $found{$_}) )
                    } keys %found,
                },
            );
    }
    return;
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

Tangerine::hook::list - Process simple module lists

=head1 DESCRIPTION

This hook catches C<use> statements with modules loading more modules
listed as their arguments.

Currently this hook knows about L<aliased>, L<base>, L<Mojo::Base>,
L<Test::use::ok>, L<parent>, L<superclass> and L<Test::Class::Most>.

=head1 SEE ALSO

L<Tangerine>, L<aliased>, L<base>, L<Mojo::Base>, L<Test::use::ok>, L<parent>,
L<superclass>, L<Test::Class::Most><commit_msg>Add support for simple `mixin' to the list hook as well<commit_after>package Tangerine::hook::list;

use 5.010;
use strict;
use warnings;
use parent 'Tangerine::Hook';
use List::Util 1.33 qw(any);
use Tangerine::HookData;
use Tangerine::Occurence;
use Tangerine::Utils qw(stripquotelike $vre);

sub run {
    my ($self, $s) = @_;
    if ((any { $s->[0] eq $_ } qw(use no)) && scalar(@$s) > 2 &&
        (any { $s->[1] eq $_ }
            qw(aliased base mixin mixin::with Mojo::Base ok parent superclass
               Test::Class::Most))) {
        my ($version) = $s->[2] =~ $vre;
        $version //= '';
        my $voffset = $version ? 3 : 2;
        my @args;
        if (scalar(@$s) > $voffset) {
            return if $s->[$voffset] eq ';';
            @args = @$s;
            @args = @args[($voffset) .. $#args];
            @args = stripquotelike(@args);
            @args = grep { !/^-norequire$/ } @args
                if any { $s->[1] eq $_ } qw/parent superclass/;
            @args = grep { !/^-(base|strict)$/ } @args
                if $s->[1] eq 'Mojo::Base';
        }
        @args = $args[0]
            if $args[0] && any { $s->[1] eq $_ }
                qw/aliased mixin mixin::with Mojo::Base ok/;
        if ($s->[1] eq 'Test::Class::Most') {
            my $tcmparent;
            my @results;
            for my $arg (@args) {
                if ($tcmparent) {
                    if (any { $arg eq $_ } qw/attributes is_abstract/) {
                        undef $tcmparent;
                        next
                    }
                    push @results, $arg
                } else {
                    if ($arg eq 'parent') {
                        $tcmparent++;
                        undef @results
                    }
                }
            }
            @args = @results
        }
        my %found;
        for (my $i = 0; $i < scalar(@args); $i++) {
            $found{$args[$i]} = '';
            if ($args[$i+1] && $args[$i+1] =~ /^v?\d+(?:\.\d+)*$/) {
                $found{$args[$i]} = $args[$i+1];
                $i++
            }
        }
        return Tangerine::HookData->new(
            modules => {
                map {
                    ( $_ => Tangerine::Occurence->new(version => $found{$_}) )
                    } keys %found,
                },
            );
    }
    return;
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

Tangerine::hook::list - Process simple module lists

=head1 DESCRIPTION

This hook catches C<use> statements with modules loading more modules
listed as their arguments.

Currently this hook knows about L<aliased>, L<base>, L<mixin>, L<mixin::with>,
L<Mojo::Base>, L<Test::use::ok>, L<parent>, L<superclass> and
L<Test::Class::Most>.

=head1 SEE ALSO

L<Tangerine>, L<aliased>, L<base>, L<mixin>, L<mixin::with>, L<Mojo::Base>,
L<Test::use::ok>, L<parent>, L<superclass>, L<Test::Class::Most>
{'fraction_non_alphanumeric': 0.1741731175228712, 'fraction_numerical': 0.009852216748768473, 'mean_word_length': 1.5758948799275034, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5418457', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1835, 'n_words': 447}