#!/usr/bin/perl

package Perl6::Declare::Meta::Method;
use Moose;

extends qw(
    Perl6::Declare::Meta::Code
    Moose::Meta::Method
);

after install => sub {
    my ( $self, %args ) = @_;

    my ( $class, $short_name ) = ( $args{name} =~ /(.*)::(.*)/ );

    return unless $class->can("meta");

    my $metaclass = $class->meta;

    $metaclass->get_method_map->{$short_name} = $self; # FECK!!! $pkg->meta->add_method($meta) breaks. FUCK YOU STEVAN!
};

around prelude_parts => sub {
    my ( $next, $self, @args ) = @_;
    return ( "prelude_invocant", $self->$next(@args) );
};

sub prelude_invocant {
    my ( $self ) = @_;
    my $invocant_var = $self->p6_sig->s_invocant ? $self->p6_sig->s_invocant->p_variable : '$self';
    return "my $invocant_var = shift; ";
}

__PACKAGE__

__END__

=pod

=head1 NAME

Perl6::Declare::Meta::Method - 

=head1 SYNOPSIS

	use Perl6::Declare::Meta::Method;

=head1 DESCRIPTION

=cut


