<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.


##################
#Bugzilla Test 10#
## dependencies ##

use 5.14.0;
use strict;
use warnings;

use lib qw(. lib local/lib/perl5 t);

use Support::Files;
use Test::More qw(no_plan);

my %mods;
my %deps;

use constant MODULE_REGEX => qr/
    (?:(?:^\s*use)
       |
       (?:^require)
    )\s+
    ['"]?
    ([\w:\.\\]+)
/x;
use constant BASE_REGEX => qr/^use (?:base|parent) (?:-norequire, )?qw\(([^\)]+)/;

# Extract all Perl modules.
foreach my $file (@Support::Files::testitems) {
  if ($file =~ /^(.*)\.pm$/) {
    my $module = $1;
    $module =~ s#/#::#g;
    $mods{$module} = $file;
  }
}

foreach my $module (keys %mods) {
    my $reading = 1;
    my @use;

    open(SOURCE, $mods{$module});
    while (my $line = <SOURCE>) {
      last if ($line =~ /^__END__/);
      if ($line =~ /^=cut/) {
        $reading = 1;
        next;
      }
      next unless $reading;
      if ($line =~ /^=(head|over|item|back|pod|begin|end|for)/) {
        $reading = 0;
        next;
      }
      if ($line =~ /^package\s+([^;]);/) {
        $module = $1;
      }
      elsif ($line =~ BASE_REGEX or $line =~ MODULE_REGEX) {
        my $used_string = $1;
        # "use base"/"use parent" can have multiple modules
        my @used_array = split(/\s+/, $used_string);
        foreach my $used (@used_array) {
            next if $used !~ /^Bugzilla/;
            $used =~ s#/#::#g;
            $used =~ s#\.pm$##;
            $used =~ s#\$module#[^:]+#;
            $used =~ s#\${[^}]+}#[^:]+#;
            $used =~ s#[" ]##g;
            push(@use, grep(/^\Q$used\E$/, keys %mods));
        }
      }
    }
    close (SOURCE);

    foreach my $u (@use) {
      if (!grep {$_ eq $u} @{$deps{$module}}) {
        push(@{$deps{$module}}, $u);
      }
    }
}

sub creates_loop {<commit_msg>Bug 228444 - Checking for unquoted non regex variable interpolated into regex<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.


##################
#Bugzilla Test 10#
## dependencies ##

use 5.14.0;
use strict;
use warnings;

use lib qw(. lib local/lib/perl5 t);

use Support::Files;
use Test::More qw(no_plan);

my %mods;
my %deps;

use constant MODULE_REGEX => qr/
    (?:(?:^\s*use)
       |
       (?:^require)
    )\s+
    ['"]?
    ([\w:\.\\]+)
/x;
use constant BASE_REGEX => qr/^use (?:base|parent) (?:-norequire, )?qw\(([^\)]+)/;

# Extract all Perl modules.
foreach my $file (@Support::Files::testitems) {
  if ($file =~ /^(.*)\.pm$/) {
    my $module = $1;
    $module =~ s#/#::#g;
    $mods{$module} = $file;
  }
}

foreach my $module (keys %mods) {
    my $reading = 1;
    my @use;

    open(SOURCE, $mods{$module});
    while (my $line = <SOURCE>) {
      last if ($line =~ /^__END__/);
      if ($line =~ /^=cut/) {
        $reading = 1;
        next;
      }
      next unless $reading;
      if ($line =~ /^=(head|over|item|back|pod|begin|end|for)/) {
        $reading = 0;
        next;
      }
      if ($line =~ /^package\s+([^;]);/) {
        $module = $1;
      }
      elsif ($line =~ BASE_REGEX or $line =~ MODULE_REGEX) {
        my $used_string = $1;
        # "use base"/"use parent" can have multiple modules
        my @used_array = split(/\s+/, $used_string);
        foreach my $used (@used_array) {
            next if $used !~ /^Bugzilla/;
            $used =~ s#/#::#g;
            $used =~ s#\.pm$##;
            $used =~ s#\$module#[^:]+#;
            $used =~ s#\$\{[^}]+}#[^:]+#;
            $used =~ s#[" ]##g;
            push(@use, grep(/^\Q$used\E$/, keys %mods));
        }
      }
    }
    close (SOURCE);

    foreach my $u (@use) {
      if (!grep {$_ eq $u} @{$deps{$module}}) {
        push(@{$deps{$module}}, $u);
      }
    }
}

sub creates_loop {
{'fraction_non_alphanumeric': 0.2134387351778656, 'fraction_numerical': 0.010230179028132993, 'mean_word_length': 2.1866666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4850846', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1585, 'n_words': 430}