<commit_before>package Silki::Markdent::Handler::ExtractWikiLinks;

use strict;
use warnings;
use namespace::autoclean;

our $VERSION = '0.01';

use List::AllUtils qw( any );
use Silki::Types qw( HashRef );

use Moose;
use MooseX::SemiAffordanceAccessor;
use MooseX::StrictConstructor;

with 'Markdent::Role::Handler', 'Silki::Markdent::Role::WikiLinkResolver';

has links => (
    traits   => ['Hash'],
    is       => 'ro',
    isa      => HashRef[HashRef],
    init_arg => undef,
    default  => sub { {} },
    handles  => {
        _add_link => 'set',
    },
);

my @types = map { 'Silki::Markdent::Event::' . $_ } qw( WikiLink FileLink ImageLink );

sub handle_event {
    my $self  = shift;
    my $event = shift;

    return unless any {  $event->isa($_) } @types;

    my $link_data;
    if ( $event->isa('Silki::Markdent::Event::WikiLink') ) {
        $link_data = $self->_resolve_page_link( $event->link_text() );
    }
    else {
        $link_data = $self->_resolve_file_link( $event->link_text() );
    }

    return unless $link_data && ( $link_data->{page} || $link_data->{file} );

    $self->_add_link( $event->link_text() => $link_data );

    return;
}

1;<commit_msg>Unbreak link extractor<commit_after>package Silki::Markdent::Handler::ExtractWikiLinks;

use strict;
use warnings;
use namespace::autoclean;

our $VERSION = '0.01';

use List::AllUtils qw( any );
use Silki::Types qw( HashRef );

use Moose;
use MooseX::SemiAffordanceAccessor;
use MooseX::StrictConstructor;

with 'Markdent::Role::Handler', 'Silki::Markdent::Role::WikiLinkResolver';

has links => (
    traits   => ['Hash'],
    is       => 'ro',
    isa      => HashRef[HashRef],
    init_arg => undef,
    default  => sub { {} },
    handles  => {
        _add_link => 'set',
    },
);

my @types = map { 'Silki::Markdent::Event::' . $_ } qw( WikiLink FileLink ImageLink );

sub handle_event {
    my $self  = shift;
    my $event = shift;

    return unless any {  $event->isa($_) } @types;

    my $link_data;
    if ( $event->isa('Silki::Markdent::Event::WikiLink') ) {
        $link_data = $self->_resolve_page_link( $event->link_text() );
    }
    else {
        $link_data = $self->_resolve_file_link( $event->link_text() );
    }

    return unless $link_data && $link_data->{wiki};

    $self->_add_link( $event->link_text() => $link_data );

    return;
}

1;
{'fraction_non_alphanumeric': 0.17592200084781687, 'fraction_numerical': 0.003391267486222976, 'mean_word_length': 3.4029850746268657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 40, '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': '6262974', 'n_tokens_mistral': 862, 'n_tokens_neox': 838, 'n_words': 170}