
package Text::Wigwam::Engine::Common::Directives;

    # Inherent directives
    use strict;
    use warnings;
    no warnings q/uninitialized/;
    no warnings q/recursion/;
    our $VERSION = '0.01';

    use base q/Exporter/;

    use Text::Wigwam::Const(
      qw/
        BOOLEAN STRING HASH ARRAY VAR
        OPTIONAL BLESSED VOID TERM ANY
      /
    );

    our %EXPORT_TAGS = (
        all => [
          qw/
            _proto_Do           _Do
            _proto_List         _List
            _proto_Qw           _Qw
            _proto_Array        _Array
            _proto_Any          _Any
            _proto_Hash         _Hash
            _proto_Scalar       _Scalar
            _proto_Boolean      _Boolean
            _proto_Invoke       _Invoke
            _proto_InvokeClass  _InvokeClass
          /
        ],
        standard => [
          qw/
            _proto_Do           _Do
            _proto_List         _List
            _proto_Qw           _Qw
            _proto_Array        _Array
            _proto_Any          _Any
            _proto_Hash         _Hash
            _proto_Scalar       _Scalar
            _proto_Boolean      _Boolean
          /
        ],
    );
    our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
    our @EXPORT = qw( );

# Braces, code tags, text blocks, and global text block
    sub _proto_Do { [ TERM|STRING|VOID ] }
    sub _Do { return join( "" => @{$_[0]->get_arg} ) }

# List/Array Parenthesis ()
    sub _proto_List { [ TERM|ANY ] }
    sub _List { return [@{$_[0]->get_arg}] }

# Quote words, aliased to < >
    sub _proto_Qw { [ TERM|VAR ] }
    sub _Qw { return [@{$_[0]->get_arg}] }

# Aliased to %
    sub _proto_Hash { [ HASH ] }
    sub _Hash { $_[0]->get_arg }

# Aliased to @
    sub _proto_Array { [ ARRAY ] }
    sub _Array { $_[0]->get_arg }

# Aliased to *
    sub _proto_Any { [ ANY ] }
    sub _Any { $_[0]->get_arg }

# Aliased to $
    sub _proto_Scalar { [ STRING ] }
    sub _Scalar { $_[0]->get_arg }

# Aliased to ?
    sub _proto_Boolean { [ BOOLEAN ] }
    sub _Boolean { $_[0]->get_arg }

# Handles var->method()
    sub _proto_Invoke { [ BLESSED, STRING, ARRAY|OPTIONAL ] }
    sub _Invoke {
        my ($Api, $list_contx) = @_;
        my $obj = $Api->get_arg;
        my $met = $Api->interpolate( $Api->get_arg );
        return scalar $obj->$met( @{$Api->get_arg} ) unless $list_contx;
        my @result = $obj->$met( @{$Api->get_arg} );
        return scalar @result > 1 ? \@result : $result[0];
    }

# Handles "class"->method()
    sub _proto_InvokeClass { [ STRING, STRING, ARRAY|OPTIONAL ] }
    sub _InvokeClass {
        my ($Api, $list_contx) = @_;
        my $obj = $Api->get_arg;
        my $met = $Api->interpolate( $Api->get_arg );
        return scalar $obj->$met( @{$Api->get_arg} ) unless $list_contx;
        my @result = $obj->$met( @{$Api->get_arg} );
        return scalar @result > 1 ? \@result : $result[0];
    }

1;

__END__
