Compiler-Parser

 view release on metacpan or  search on metacpan

t/app/Plack/Runner.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use Compiler::Lexer;
use Compiler::Parser;
use Compiler::Parser::AST::Renderer;
use Test::Compiler::Parser;

subtest 'parse Plack/Runner.pm' => sub {
    my $script = do { local $/; <DATA> };
    my $tokens = Compiler::Lexer->new('')->tokenize($script);
    my $ast = Compiler::Parser->new->parse($tokens);
    Compiler::Parser::AST::Renderer->new->render($ast);
    node_ok($ast->root, [
        Test::Compiler::Parser::package { 'Plack::Runner',
        },
        module { 'strict',
        },
        module { 'warnings',
        },
        module { 'Carp',
            args => list { '()',
            },
        },
        module { 'Plack::Util',
        },
        module { 'Try::Tiny',
        },
        function { 'new',
            body => [
                branch { '=',
                    left => leaf '$class',
                    right => function_call { 'shift',
                        args => [
                        ],
                    },
                },
                function_call { 'bless',
                    args => [
                        branch { ',',
                            left => hash_ref { '{}',
                                data => branch { ',',
                                    left => branch { ',',
                                        left => branch { ',',
                                            left => branch { ',',
                                                left => branch { ',',
                                                    left => branch { ',',
                                                        left => branch { '=>',
                                                            left => leaf 'env',
                                                            right => hash { '$ENV',
                                                                key => hash_ref { '{}',
                                                                    data => leaf 'PLACK_ENV',
                                                                },
                                                            },
                                                        },
                                                        right => branch { '=>',
                                                            left => leaf 'loader',
                                                            right => leaf 'Plack::Loader',
                                                        },
                                                    },
                                                    right => branch { '=>',
                                                        left => leaf 'includes',
                                                        right => array_ref { '[]',
                                                        },
                                                    },
                                                },
                                                right => branch { '=>',
                                                    left => leaf 'modules',
                                                    right => array_ref { '[]',
                                                    },
                                                },
                                            },
                                            right => branch { '=>',
                                                left => leaf 'default_middleware',
                                                right => leaf '1',
                                            },
                                        },
                                        right => leaf '@_',
                                    },
                                },
                            },
                            right => leaf '$class',
                        },
                    ],
                },
            ],
        },

t/app/Plack/Runner.t  view on Meta::CPAN

                                                },
                                            },
                                        },
                                    ],
                                },
                            },
                        },
                    ],
                },
                branch { '=',
                    left => leaf '$loader',
                    right => branch { '->',
                        left => leaf '$self',
                        right => function_call { 'loader',
                            args => [
                            ],
                        },
                    },
                },
                branch { '->',
                    left => leaf '$loader',
                    right => function_call { 'preload_app',
                        args => [
                            leaf '$app',
                        ],
                    },
                },
                branch { '=',
                    left => leaf '$server',
                    right => branch { '->',
                        left => leaf '$self',
                        right => function_call { 'load_server',
                            args => [
                                leaf '$loader',
                            ],
                        },
                    },
                },
                branch { '->',
                    left => leaf '$loader',
                    right => function_call { 'run',
                        args => [
                            leaf '$server',
                        ],
                    },
                },
            ],
        },
        leaf '1',
    ]);
};

done_testing;

__DATA__
package Plack::Runner;
use strict;
use warnings;
use Carp ();
use Plack::Util;
use Try::Tiny;

sub new {
    my $class = shift;
    bless {
        env      => $ENV{PLACK_ENV},
        loader   => 'Plack::Loader',
        includes => [],
        modules  => [],
        default_middleware => 1,
        @_,
    }, $class;
}

# delay the build process for reloader
sub build(&;$) {
    my $block = shift;
    my $app   = shift || sub { };
    return sub { $block->($app->()) };
}

sub parse_options {
    my $self = shift;

    local @ARGV = @_;

    # From 'prove': Allow cuddling the paths with -I, -M and -e
    @ARGV = map { /^(-[IMe])(.+)/ ? ($1,$2) : $_ } @ARGV;

    my($host, $port, $socket, @listen);

    require Getopt::Long;
    my $parser = Getopt::Long::Parser->new(
        config => [ "no_auto_abbrev", "no_ignore_case", "pass_through" ],
    );

    $parser->getoptions(
        "a|app=s"      => \$self->{app},
        "o|host=s"     => \$host,
        "p|port=i"     => \$port,
        "s|server=s"   => \$self->{server},
        "S|socket=s"   => \$socket,
        'l|listen=s@'  => \@listen,
        'D|daemonize'  => \$self->{daemonize},
        "E|env=s"      => \$self->{env},
        "e=s"          => \$self->{eval},
        'I=s@'         => $self->{includes},
        'M=s@'         => $self->{modules},
        'r|reload'     => sub { $self->{loader} = "Restarter" },
        'R|Reload=s'   => sub { $self->{loader} = "Restarter"; $self->loader->watch(split ",", $_[1]) },
        'L|loader=s'   => \$self->{loader},
        "access-log=s" => \$self->{access_log},
        "path=s"       => \$self->{path},
        "h|help"       => \$self->{help},
        "v|version"    => \$self->{version},
        "default-middleware!" => \$self->{default_middleware},
    );

    my(@options, @argv);
    while (defined(my $arg = shift @ARGV)) {
        if ($arg =~ s/^--?//) {



( run in 0.482 second using v1.01-cache-2.11-cpan-5fbc6bb55f2 )