<commit_before>package Fey::Column::Alias;

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

our $VERSION = '0.41';

use Fey::Column;
use Fey::Exceptions qw( object_state_error );
use Fey::Table;
use Fey::Table::Alias;
use Fey::Types qw( Column Str );

use Moose 0.90;
use MooseX::SemiAffordanceAccessor 0.03;
use MooseX::StrictConstructor 0.07;

with 'Fey::Role::ColumnLike';

has 'id' => (
    is         => 'ro',
    lazy_build => 1,
    init_arg   => undef,
    clearer    => '_clear_id',
);

has 'column' => (
    is      => 'ro',
    isa     => Column,
    handles => [
        qw( name type generic_type length precision
            is_auto_increment is_nullable table )
    ],
);

has 'alias_name' => (
    is         => 'ro',
    isa        => Str,
    lazy_build => 1,
);

with 'Fey::Role::Named';

{
    my %Numbers;

    sub _build_alias_name {
        my $self = shift;

        my $name = $self->name();
        $Numbers{$name} ||= 0;

        return $name . ++$Numbers{$name};
    }
}

sub is_alias {1}

sub sql { $_[1]->quote_identifier( $_[0]->alias_name() ) }

sub sql_with_alias {
    my $sql = $_[1]->quote_identifier(
        undef,
        $_[0]->_containing_table_name_or_alias(),
        $_[0]->name(),
    );

    $sql .= ' AS ';
    $sql .= $_[1]->quote_identifier( $_[0]->alias_name() );

    return $sql;
}

sub sql_or_alias { goto &sql }

sub _build_id {
    my $self = shift;

    my $table = $self->table();

    object_state_error
        'The id attribute cannot be determined for a column object which has no table.'
        unless $table;

    return $table->id() . '.' . $self->alias_name();
}

__PACKAGE__->meta()->make_immutable();
<commit_msg>Avoid a circular use between Fey::Column and Fey::Column::Alias<commit_after>package Fey::Column::Alias;

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

our $VERSION = '0.41';

use Fey::Exceptions qw( object_state_error );
use Fey::Table;
use Fey::Table::Alias;
use Fey::Types qw( Column Str );

use Moose 0.90;
use MooseX::SemiAffordanceAccessor 0.03;
use MooseX::StrictConstructor 0.07;

with 'Fey::Role::ColumnLike';

has 'id' => (
    is         => 'ro',
    lazy_build => 1,
    init_arg   => undef,
    clearer    => '_clear_id',
);

has 'column' => (
    is      => 'ro',
    isa     => Column,
    handles => [
        qw( name type generic_type length precision
            is_auto_increment is_nullable table )
    ],
);

has 'alias_name' => (
    is         => 'ro',
    isa        => Str,
    lazy_build => 1,
);

with 'Fey::Role::Named';

{
    my %Numbers;

    sub _build_alias_name {
        my $self = shift;

        my $name = $self->name();
        $Numbers{$name} ||= 0;

        return $name . ++$Numbers{$name};
    }
}

sub is_alias {1}

sub sql { $_[1]->quote_identifier( $_[0]->alias_name() ) }

sub sql_with_alias {
    my $sql = $_[1]->quote_identifier(
        undef,
        $_[0]->_containing_table_name_or_alias(),
        $_[0]->name(),
    );

    $sql .= ' AS ';
    $sql .= $_[1]->quote_identifier( $_[0]->alias_name() );

    return $sql;
}

sub sql_or_alias { goto &sql }

sub _build_id {
    my $self = shift;

    my $table = $self->table();

    object_state_error
        'The id attribute cannot be determined for a column object which has no table.'
        unless $table;

    return $table->id() . '.' . $self->alias_name();
}

__PACKAGE__->meta()->make_immutable();

# This is here to avoid a circular use issue.
require Fey::Column;

{'fraction_non_alphanumeric': 0.1635473653901526, 'fraction_numerical': 0.013245033112582781, 'mean_word_length': 2.649159663865546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, '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': '3590004', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1231, 'n_words': 304}