package MooseX::Sub::Arguments::Common;
use warnings;
use strict;

use Devel::Caller   qw( called_as_method );
use Scalar::Util    qw( blessed );
use namespace::clean;

sub caller_args_start {
    my ($class) = @_;
    return called_as_method(2) ? 1 : 0;
}

my %InvocantLookup = (
    CLASS       => sub { shift },
    SELF        => sub { shift },
    SELF_CLASS  => sub { blessed(shift) },
);

sub process_invocant_args {
    my ($class, $call_type, $struct, $flags, $args) = @_;
    my $inv = $args->[0];
    return map { $InvocantLookup{ $_->[1][0] }->($inv) } @$struct;
}

1;
