<commit_before>class Attribute is Any;

has $!name;
has $!type;
has $!build;
has $!has_accessor;
has $!rw;
has $!handles;
has $!trait_applier;

method new(:$name, :$type, :$build, :$has_accessor, :$rw, :$handles) {
    my $attr := pir::new__PS('Attribute');
    pir::setattribute__vPSP($attr, '$!name', $name);
    pir::setattribute__vPSP($attr, '$!type', $type);
    pir::setattribute__vPSP($attr, '$!build', $build);
    pir::setattribute__vPSP($attr, '$!has_accessor', $has_accessor);
    pir::setattribute__vPSP($attr, '$!rw', $rw);
    pir::setattribute__vPSP($attr, '$!handles', $handles);
    $attr
}

method name() {
    $!name
}

method type() {
    $!type
}

method build() {
    $!build || Mu
}

method has_accessor() {
    $!has_accessor
}

method rw() {
    $!rw
}

method handles() {
    $!handles
}

method readonly() {
    !$!rw
}

method apply_traits($metaclass, $container) {
    if $!trait_applier {
        my $decl := AttributeDeclarand.new(
            container => $container,
            how => $metaclass,
            name => $!name
        );
        $!trait_applier($decl);
    }
}

method compose($package) {
    my $name := $!name;
    
    # Generate an accessor, if we need one.
    if $!has_accessor {
        # Accessor helper subs.
        sub accessor_helper_ro($self) {
            pir::new__PsP('Perl6Scalar', pir::getattribute__PPS($self, $name))
        }
        sub accessor_helper_rw($self) {
            pir::getattribute__PPS($self, $name)
        }

        # XXX check there isn't already one...
        my $meth := $!rw ?? pir::find_lex__Ps('accessor_helper_rw') !! pir::find_lex__Ps('accessor_helper_ro');
        my $meth_name := pir::substr__SSi($name, 2);
        $meth := pir::clone($meth);

        # introspection looks at the actual sub name, so set it
        # to the value the user expects
        # set $P0, $S0  is parrot's clunky PIR API for setting the sub name.
        pir::set__vps($meth, $meth_name);
        $package.add_method($package, $meth_name, $meth);
    }

    # If we've a handles, pass it along to the handles setup helper.
    unless pir::isa__ips($!handles, 'Undef') {<commit_msg>If the attribute doesn't explicitly have rw or readonly specified, fall back and ask the package if it has an interesting default.<commit_after>class Attribute is Any;

has $!name;
has $!type;
has $!build;
has $!has_accessor;
has $!rw;
has $!handles;
has $!trait_applier;

method new(:$name, :$type, :$build, :$has_accessor, :$rw, :$handles) {
    my $attr := pir::new__PS('Attribute');
    pir::setattribute__vPSP($attr, '$!name', $name);
    pir::setattribute__vPSP($attr, '$!type', $type);
    pir::setattribute__vPSP($attr, '$!build', $build);
    pir::setattribute__vPSP($attr, '$!has_accessor', $has_accessor);
    pir::setattribute__vPSP($attr, '$!rw', $rw);
    pir::setattribute__vPSP($attr, '$!handles', $handles);
    $attr
}

method name() {
    $!name
}

method type() {
    $!type
}

method build() {
    $!build || Mu
}

method has_accessor() {
    $!has_accessor
}

method rw() {
    $!rw
}

method handles() {
    $!handles
}

method readonly() {
    !$!rw
}

method apply_traits($metaclass, $container) {
    if $!trait_applier {
        my $decl := AttributeDeclarand.new(
            container => $container,
            how => $metaclass,
            name => $!name
        );
        $!trait_applier($decl);
    }
}

method compose($package) {
    my $name := $!name;
    
    # Generate an accessor, if we need one.
    if $!has_accessor {
        # Accessor helper subs.
        sub accessor_helper_ro($self) {
            pir::new__PsP('Perl6Scalar', pir::getattribute__PPS($self, $name))
        }
        sub accessor_helper_rw($self) {
            pir::getattribute__PPS($self, $name)
        }

        # XXX check there isn't already one...

        # Decide whether we want an rw one or not.
        my $is_rw := pir::defined($!rw) ?? $!rw !!
                     pir::can__ips($package, 'rw') ?? $package.rw !! 0;
        my $meth := pir::find_lex__ps($is_rw ?? 'accessor_helper_rw' !! 'accessor_helper_ro');
        $meth := pir::clone($meth);

        # introspection looks at the actual sub name, so set it
        # to the value the user expects
        # set $P0, $S0  is parrot's clunky PIR API for setting the sub name.
        my $meth_name := pir::substr__SSi($name, 2);
        pir::set__vps($meth, $meth_name);
        $package.add_method($package, $meth_name, $meth);
    }

    # If we've a handles, pass it along to the handles setup helper.
    unless pir::isa__ips($!handles, 'Undef') {
{'fraction_non_alphanumeric': 0.16024384933594601, 'fraction_numerical': 0.001959503592423253, 'mean_word_length': 2.9399656946826758, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5496510', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1600, 'n_words': 390}