package selfless;
use strict;

=head1 NAME

selfless - 

=head1 SYNOPSIS

 package Fnord;
 use selfless;
 sub foo {
     Carp::cluck;
     warn "$self: ".join(',',@_);
 }

=head1 DESCRIPTION



=cut
our @orz;

sub import {
    my $class = shift;
    my $caller = caller;
    no strict 'refs';
    my $sym = "${caller}::self";
    *$sym = \$$sym;
    push @orz, $caller;
}

use Data::Bind ();
INIT {
    for my $caller (@orz) {
	no strict 'refs';
	for (keys %{$caller.'::'}) {
	    my $code = $caller->can($_) or next;
	    next if $_ eq 'isa';
	    my $their_self = $caller.'::self';
	    *{$caller.'::'.$_} = sub {
		local ${$their_self} = shift;
		Data::Bind::_forget_unlocal(1);
		goto $code;
	    };
	}
    }
}

1;
