package MooseX::Literals;

use strict;
use warnings;

our $VERSION   = '0.01';
our $AUTHORITY = 'cpan:STEVAN';

use Moose ();

my @exports = qw[
    object class
    method
    extends with has
    before after around    
];

sub import {
    my $caller = caller();
    no strict 'refs';    
    foreach my $export (@exports) {
        unless (*{"${caller}::${export}"}{CODE}) {
            *{"${caller}::${export}"} = \&{$export}
        }
        else {
            # NOTE:
            # we need to re-subname them 
            # in order for this to work
            # otherwise Moose will reap 
            # the symbols from the pacakge
            # and that causes issues.
            # - SL 
            *{"${caller}::${export}"} = Class::MOP::subname(
                "MooseX::Literal::${export}" => \&{"${caller}::${export}"}
            );
        }
    }
}

sub class (&@) {
    my $caller = caller();
    # in case object is calling us
    ($caller)  = caller(1) if $caller eq __PACKAGE__;
    my $body   = shift;
    
    my $meta = Moose::Meta::Class->create_anon_class(
        superclasses => [ 'Moose::Object' ],
    );
    $meta->add_method(meta => sub { $meta });

    my @keywords = qw[
        extends with has
        before after around
    ];

    my %exports = Moose::__CURRY_EXPORTS_FOR_CLASS__(
        $meta->name => @keywords
    );
    
    no strict 'refs';
    no warnings 'redefine';

    local *{"${caller}::extends"} = $exports{'extends'};
    local *{"${caller}::with"}    = $exports{'with'};    
    local *{"${caller}::has"}     = $exports{'has'};            
    local *{"${caller}::around"}  = $exports{'around'};    
    local *{"${caller}::before"}  = $exports{'before'}; 
    local *{"${caller}::after"}   = $exports{'after'};         
    local *{"${caller}::method"}  = sub ($&) { $meta->add_method(@_) };
    
    $body->($meta);
    
    return $meta;    
}

sub object (&@) { &class(shift)->name->new(@_) }

sub extends (@)   {}
sub with    (@)   {}
sub has     ($;%) {}
sub before  (@&)  {}
sub after   (@&)  {}
sub around  (@&)  {}
sub method  ($&)  {}

1;

__END__

=pod

=head1 NAME

MooseX::Literals - A Moosey solution to this problem

=head1 SYNOPSIS

  use MooseX::Literals;

=head1 DESCRIPTION

=head1 METHODS 

=over 4

=item B<>

=back

=head1 BUGS

All complex software has bugs lurking in it, and this module is no 
exception. If you find a bug please either email me, or add the bug
to cpan-RT.

=head1 AUTHOR

Stevan Little E<lt>stevan.little@iinteractive.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2008 Infinity Interactive, Inc.

L<http://www.iinteractive.com>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
