<commit_before>package Wing::Role::Result::Field;

use Wing::Perl;
use Ouch;
use Moose::Role;

sub register_fields {
    my ($class, %fields) = @_;
    while (my ($field, $definition) = each %fields) {
        $class->register_field($field, $definition);
    }
}

sub register_field {
    my ($class, $field, $options) = @_;

    # add dbic columns
    $class->add_columns($field => $options->{dbic});
    
    # add field to postable params
    if (exists $options->{edit}) {
        if ($options->{edit} ~~ [qw(postable required unique)]) {
            $class->meta->add_around_method_modifier(postable_params => sub {
                my ($orig, $self) = @_;
                my $params = $orig->($self);
                push @$params, $field;
                return $params;
            });

            # make required
            if ($options->{edit} ~~ [qw(required unique)]) {
                $class->meta->add_around_method_modifier(required_params => sub {
                    my ($orig, $self) = @_;
                    my $params = $orig->($self);
                    push @$params, $field;
                    return $params;
                });

                # make unique
                if ($options->{edit} eq 'unique') {<commit_msg>testing for requiredness on the backend as well as the web service<commit_after>package Wing::Role::Result::Field;

use Wing::Perl;
use Ouch;
use Moose::Role;

sub register_fields {
    my ($class, %fields) = @_;
    while (my ($field, $definition) = each %fields) {
        $class->register_field($field, $definition);
    }
}

sub register_field {
    my ($class, $field, $options) = @_;

    # add dbic columns
    $class->add_columns($field => $options->{dbic});
    
    # add field to postable params
    if (exists $options->{edit}) {
        if ($options->{edit} ~~ [qw(postable required unique)]) {
            $class->meta->add_around_method_modifier(postable_params => sub {
                my ($orig, $self) = @_;
                my $params = $orig->($self);
                push @$params, $field;
                return $params;
            });

            # make required
            if ($options->{edit} ~~ [qw(required unique)]) {
                $class->meta->add_around_method_modifier(required_params => sub {
                    my ($orig, $self) = @_;
                    my $params = $orig->($self);
                    push @$params, $field;
                    return $params;
                });
                $class->meta->add_before_method_modifier(deck_id => sub {
                    if (scalar @_ == 2 && ! defined $_[1]) {
                        ouch 441, $field.' is required.', $field;
                    }
                });
                
                # make unique
                if ($options->{edit} eq 'unique') {
{'fraction_non_alphanumeric': 0.1499644633972992, 'fraction_numerical': 0.0017768301350390902, 'mean_word_length': 1.7171814671814671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '640358', 'n_tokens_mistral': 826, 'n_tokens_neox': 791, 'n_words': 190}