package Web::Simple::Application; use Scalar::Util 'weaken'; use
Moo; has 'config' => ( is => 'ro', default => sub { my ($self) =
@_; +{ $self->default_config } }, trigger => sub { my ($self,
$value) = @_; my %default = $self->default_config; my @not =
grep !exists $value->{$_}, keys %default; @{$value}{@not} =
@default{@not}; } ); sub default_config { () } has '_dispatcher'
=> (is => 'lazy'); sub _build__dispatcher { my $self = shift;
require Web::Dispatch; my $final =
$self->_build_final_dispatcher; # We need to weaken both the
copy of $self that the # app parameter will close over and the
copy that'll # be passed through as a node argument. # # To
ensure that this doesn't then result in us being # DESTROYed
unexpectedly early, our to_psgi_app method # closes back over
$self weaken($self); my %dispatch_args = ( dispatch_app => sub {
$self->dispatch_request(@_), $final }, dispatch_object => $self
); weaken($dispatch_args{dispatch_object});
Web::Dispatch->new(%dispatch_args); } sub
_build_final_dispatcher { [