<commit_before># Copyright (c) 2015, <NAME>
package Ferret::Core::Specials;

use warnings;
use strict;
use utf8;
use 5.010;

use Ferret::Core::Conversion qw(
    flist_wrap flist fbool
    pdescription pstring fnumber fstring
);

my %specials = (
    self            => \&_self,
    isa             => \&_isa,
    classes         => \&_classes,
    ownProperties   => \&_ownProperties,
    allProperties   => \&_allProperties,
    instanceOf      => _function('instanceOf', '$class'),
    fitsType        => _function('fitsType', '$type'),
    get             => _function('get', '$property:Str'),
    getOwn          => _function('getOwn', '$property:Str'),
    set             => _function('set', '$property:Str $value'),
    commonClass     => _function('commonClass', '$other:Object'),
    fullName        => _function('fullName', '$property:Str'),
    description     => \&_description,
    addr            => \&_addr
);

@Ferret::specials{keys %specials} = values %specials;

sub _function {
    my ($name, $need, $want) = @_;
    return sub {
        my $obj  = shift;
        my $f    = $obj->f;
        my $func = $f->{_specials}{$name};
        if (!$func) {
            $func = $f->{_specials}{$name} = Ferret::Function->new($f,
                name => $name,
                need => $need,
                want => $want,
                code => __PACKAGE__->can("_$name")
            );
        }
        $f->{_specials}{$name}{force_self} = $obj;
        return $f->{_specials}{$name};
    };
}

sub _self {
    my $obj = shift;
    return $obj;
}

# returns mutable ISA list.
sub _isa {
    my $obj = shift;
    return $obj->{_isa_ferret} if $obj->{_isa_ferret};
    my $list = flist_wrap($obj->{isa});

    # as a function, it tests whether it's an instance of a class
    $list->set_property(toFunction => Ferret::Function->new($obj->f,
        name => 'toFunction',
        code => sub { $specials{instanceOf}($obj) }
    ));

    return $obj->{_isa_ferret} = $list;
}

# returns immutable class list.
sub _classes {
    my $obj = shift;
    return flist($obj->parent_classes);
}

sub _allProperties {
    my $obj = shift;
    return flist($obj->properties(1));
}

sub _ownProperties {
    my $obj = shift;
    return flist($obj->properties);
}

sub _instanceOf {
    my ($obj, $args) = @_;
    my $class = $args->{class};
    return fbool($obj->instance_of($class));
}<commit_msg>*isa can no longer be used as a function. use *instanceOf or *fitsType<commit_after># Copyright (c) 2015, <NAME>
package Ferret::Core::Specials;

use warnings;
use strict;
use utf8;
use 5.010;

use Ferret::Core::Conversion qw(
    flist_wrap flist fbool
    pdescription pstring fnumber fstring
);

my %specials = (
    self            => \&_self,
    isa             => \&_isa,
    classes         => \&_classes,
    ownProperties   => \&_ownProperties,
    allProperties   => \&_allProperties,
    instanceOf      => _function('instanceOf', '$class'),
    fitsType        => _function('fitsType', '$type'),
    get             => _function('get', '$property:Str'),
    getOwn          => _function('getOwn', '$property:Str'),
    set             => _function('set', '$property:Str $value'),
    commonClass     => _function('commonClass', '$other:Object'),
    fullName        => _function('fullName', '$property:Str'),
    description     => \&_description,
    addr            => \&_addr
);

@Ferret::specials{keys %specials} = values %specials;

sub _function {
    my ($name, $need, $want) = @_;
    return sub {
        my $obj  = shift;
        my $f    = $obj->f;
        my $func = $f->{_specials}{$name};
        if (!$func) {
            $func = $f->{_specials}{$name} = Ferret::Function->new($f,
                name => $name,
                need => $need,
                want => $want,
                code => __PACKAGE__->can("_$name")
            );
        }
        $f->{_specials}{$name}{force_self} = $obj;
        return $f->{_specials}{$name};
    };
}

sub _self {
    my $obj = shift;
    return $obj;
}

# returns mutable ISA list.
sub _isa {
    my $obj = shift;
    return $obj->{_isa_ferret} if $obj->{_isa_ferret};
    my $list = flist_wrap($obj->{isa});
    return $obj->{_isa_ferret} = $list;
}

# returns immutable class list.
sub _classes {
    my $obj = shift;
    return flist($obj->parent_classes);
}

sub _allProperties {
    my $obj = shift;
    return flist($obj->properties(1));
}

sub _ownProperties {
    my $obj = shift;
    return flist($obj->properties);
}

sub _instanceOf {
    my ($obj, $args) = @_;
    my $class = $args->{class};
    return fbool($obj->instance_of($class));
}
{'fraction_non_alphanumeric': 0.16774751405101598, 'fraction_numerical': 0.00432338953739732, 'mean_word_length': 2.3699927166788055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '5257348', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1529, 'n_words': 355}