Async-Template

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

       RETURN IF RESULT(r);
     END
     sub{
        use Data::Dumper; warn Dumper \@_;
        die $_[0] if($_[0]);
        print 'result: ', $_[1];
     };

# DESCRIPTION

Async::Template is the same as Template Toolkit with asynchronous interface and
with asynchronous operators ASYNC/AWAIT which can be used with any event
management system (like [AnyEvent](https://metacpan.org/pod/AnyEvent)).

To refer Template Toolkit language syntax, configure options, params and other
documentation folow this link [Template](https://metacpan.org/pod/Template).

Operators like ASYNC/AWAIT itself is not an function or something wich applied
locally at the place where it is used in the code. Such operators affect all
the code generation and the execution sequences. Any block of code cease to be
a block if at least one async operator is exists in it. Loops, blocks,
conditions, switches, and so on become different in synchronous and asynchronous
implementations.

For example a synchronous loop is continuous sequence which at the end of loop
has a transition to the begin of the loop. But the asynchronous loop is not
a continuos sequence and to do transition to the begin of loop typical loop
operators can not be used because begin and end of loop located in different
unjoined betwen each other code sequences (in a different fuctions).
This is because at the middle of the loop at the place of async operator
presents a finish of the execution and return. This return must be supported
by each of parent block statement. Execution must be returned to the very top
of the execution - to the event loop. And after awaited event condition is
reached the execution must continue from that place from which it was returned.

Therefore to develop a compiler with asynchronous operators it need to have
different synchronous and asynchronous implementation for each block operator of
language and many more. And for synchronous an asynchronous function call. This
library represent itself compiler with modified grammar based on Template
Toolkit. This library provides implementation of asynchronous operators and the
code generation and asynchronous stack management and so on, uses itself as
library for asynchronous sequences and uses Template Toolkit as library for
execution generic synchronous sequences and also uses parts modified to be
asynchronous.

## SYNC AND ASYNC BLOCKS 

Continuous sequence of execution is tеaring at the place of AWAIT operator.
The block is not only BLOCK operator statement but also IF, WHILE and etc...

Any block become asynchronous if it have at least one AWAIT operator or
another asynchronous block.

Any block is synchronous if it does not contain AWAIT operator or another
asynchronous block even if it has any amount of ASYNC opeartor

Any block does not become asynchronous if it has ASYNC operator inside
(if it has no AWAIT operator nor one or more asynchronous block).

## TODO

As mentioned above, each block of code must be implemented differently
therefore this library has asynchronous implementation for most of block
operators of Template Toolkit language but not all yet.

The block operators which is not implemented as asynchronous will work anyway
with synchronous sequences (i.e. without AWAIT operator inside of it). 

Here the list of Template Toolkit operators async implementation of which does
not checked and/or implemented:

NEXT LAST STOP

MACRO FILTER

TRY / THROW / CATCH / FINAL

PERL / RAWPERL

# AUTHOR

Serguei Okladnikov <oklaspec@gmail.com>

This [Async::Template](https://metacpan.org/pod/Async%3A%3ATemplate) package uses "Template Toolkit" ([Template](https://metacpan.org/pod/Template))
as dependency and contains small amount modified parts of "Template Toolkit"
(modified grammar and continuous synchronous code which was necessary
to split for execution asynchronous sequences). The "Template Toolkit" was
written by Andy Wardley <abw@wardley.org> and contributors, see
Template::Manual::Credits for details and repos contributors sections.

# LICENSE 

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

# POD ERRORS

lib/Async/Template.pm  view on Meta::CPAN

    END
    sub{
       use Data::Dumper; warn Dumper \@_;
       die $_[0] if($_[0]);
       print 'result: ', $_[1];
    };


=head1 DESCRIPTION

Async::Template is the same as Template Toolkit with asynchronous interface and
with asynchronous operators ASYNC/AWAIT which can be used with any event
management system (like L<AnyEvent>).

To refer Template Toolkit language syntax, configure options, params and other
documentation folow this link L<Template>.

Operators like ASYNC/AWAIT itself is not an function or something wich applied
locally at the place where it is used in the code. Such operators affect all
the code generation and the execution sequences. Any block of code cease to be
a block if at least one async operator is exists in it. Loops, blocks,
conditions, switches, and so on become different in synchronous and asynchronous
implementations.

For example a synchronous loop is continuous sequence which at the end of loop
has a transition to the begin of the loop. But the asynchronous loop is not
a continuos sequence and to do transition to the begin of loop typical loop
operators can not be used because begin and end of loop located in different
unjoined betwen each other code sequences (in a different fuctions).
This is because at the middle of the loop at the place of async operator
presents a finish of the execution and return. This return must be supported
by each of parent block statement. Execution must be returned to the very top
of the execution - to the event loop. And after awaited event condition is
reached the execution must continue from that place from which it was returned.

Therefore to develop a compiler with asynchronous operators it need to have
different synchronous and asynchronous implementation for each block operator of
language and many more. And for synchronous an asynchronous function call. This
library represent itself compiler with modified grammar based on Template
Toolkit. This library provides implementation of asynchronous operators and the
code generation and asynchronous stack management and so on, uses itself as
library for asynchronous sequences and uses Template Toolkit as library for
execution generic synchronous sequences and also uses parts modified to be
asynchronous.


=head2 SYNC AND ASYNC BLOCKS 

Continuous sequence of execution is tеaring at the place of AWAIT operator.
The block is not only BLOCK operator statement but also IF, WHILE and etc...

Any block become asynchronous if it have at least one AWAIT operator or
another asynchronous block.

Any block is synchronous if it does not contain AWAIT operator or another
asynchronous block even if it has any amount of ASYNC opeartor

Any block does not become asynchronous if it has ASYNC operator inside
(if it has no AWAIT operator nor one or more asynchronous block).


=head2 TODO

As mentioned above, each block of code must be implemented differently
therefore this library has asynchronous implementation for most of block
operators of Template Toolkit language but not all yet.

The block operators which is not implemented as asynchronous will work anyway
with synchronous sequences (i.e. without AWAIT operator inside of it). 

Here the list of Template Toolkit operators async implementation of which does
not checked and/or implemented:

NEXT LAST STOP

MACRO FILTER

TRY / THROW / CATCH / FINAL

PERL / RAWPERL


=head1 AUTHOR

Serguei Okladnikov E<lt>oklaspec@gmail.comE<gt>

This L<Async::Template> package uses "Template Toolkit" (L<Template>)
as dependency and contains small amount modified parts of "Template Toolkit"
(modified grammar and continuous synchronous code which was necessary
to split for execution asynchronous sequences). The "Template Toolkit" was
written by Andy Wardley E<lt>abw@wardley.orgE<gt> and contributors, see
Template::Manual::Credits for details and repos contributors sections.


=head1 LICENSE 

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

=cut

lib/Async/Template/Context.pm  view on Meta::CPAN

package Async::Template::Context;

#! @file
#! @author: Serguei Okladnikov <oklaspec@gmail.com>
#! @date 01.10.2012

#! This source file have functions `process_enter()` and `process_leave()`.
#! Code parts of them taken from function `process()` of template toolkit
#! library and substantially enhanced, the asynchronous processing
#! is introduced by Serguei Okladnikov <oklaspec@gmail.com>
#! Author of that original code parts is Andy Wardley <abw@wardley.org>


use strict;
use warnings;
use base 'Template::Context';
use Scalar::Util 'blessed';


lib/Async/Template/Document.pm  view on Meta::CPAN

package Async::Template::Document;

#! @file
#! @author: Serguei Okladnikov <oklaspec@gmail.com>
#! @date 23.05.2013

#! This source file have functions `process_enter()` and `process_leave()`.
#! Code parts of them taken from function `process()` of template toolkit
#! library and substantially enhanced, the asynchronous processing
#! is introduced by Serguei Okladnikov <oklaspec@gmail.com>
#! Author of that original code parts is Andy Wardley <abw@wardley.org>


use strict;
use warnings;
use base 'Template::Document';
use Template::Constants;


lib/Async/Template/Grammar.pm  view on Meta::CPAN

#============================================================= -*-Perl-*-
#
# Async::Template::Grammar
#
# DESCRIPTION
#   This file based on Template::Grammar ftom Template Toolkit
#   Grammar file for the Template Toolkit language containing token
#   definitions and parser state/rules tables generated by Parse::Yapp.
#
#   This grammar taken ftom Template perl library and modified by Serguei
#   Okladnikov to integrate asynchronous EVENT, ASYNC and AWAIT operators
#
# AUTHORS
#   Andy Wardley   <abw@wardley.org>
#   Serguei Okladnikov <oklaspec@gmail.com> (EVENT/ASYNC/AWAIT and some more)
#
# COPYRIGHT
#   Copyright (C) 1996-2006 Andy Wardley.  All Rights Reserved.
#   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#   Copyright (C) 2012-2017 Serguei Okladnikov
#

parser/Grammar.pm.skel  view on Meta::CPAN

#============================================================= -*-Perl-*-
#
# Async::Template::Grammar
#
# DESCRIPTION
#   This file based on Template::Grammar ftom Template Toolkit
#   Grammar file for the Template Toolkit language containing token
#   definitions and parser state/rules tables generated by Parse::Yapp.
#
#   This grammar taken ftom Template perl library and modified by Serguei
#   Okladnikov to integrate asynchronous EVENT, ASYNC and AWAIT operators
#
# AUTHORS
#   Andy Wardley   <abw@wardley.org>
#   Serguei Okladnikov <oklaspec@gmail.com> (EVENT/ASYNC/AWAIT and some more)
#
# COPYRIGHT
#   Copyright (C) 1996-2006 Andy Wardley.  All Rights Reserved.
#   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#   Copyright (C) 2012-2017 Serguei Okladnikov
#

parser/Parser.yp  view on Meta::CPAN

#============================================================= -*-Perl-*-
#
# Parser.yp
#
# DESCRIPTION
#   Definition of the parser grammar for the Template Toolkit language.
#
#   This grammar teken ftom Template perl library and modified by Serguei
#   Okladnikov to integrate asynchronous EVENT, ASYNC and AWAIT operators
#
# AUTHOR
#   Andy Wardley <abw@wardley.org> 
#   Serguei Okladnikov <oklaspec@gmail.com> (EVENT/ASYNC/AWAIT and some more)
#
# HISTORY
#   Totally re-written for version 2, based on Doug Steinwand's 
#   implementation which compiles templates to Perl code.  The generated
#   code is _considerably_ faster, more portable and easier to process.
#



( run in 0.900 second using v1.01-cache-2.11-cpan-0d8aa00de5b )