Amon2

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

share/flavor/Minimum/lib/__PATH__/Web/ViewFunctions.pm
share/flavor/Minimum/minil.toml
share/flavor/Minimum/script/server.pl
share/flavor/Minimum/t/00_compile.t
share/flavor/Minimum/t/01_root.t
share/flavor/Minimum/t/02_mech.t
share/flavor/Minimum/t/Util.pm
share/flavor/Minimum/tmpl/index.tx
share/flavor/Minimum/xt/01_pod.t
t/00_compile.t
t/100_core/001_request_param_decoded.t
t/100_core/002_response.t
t/100_core/003_redirect.t
t/100_core/004_web_to_app_leak.t
t/100_core/005_trigger.t
t/100_core/008_request_uri_with.t
t/100_core/009_uri_for.t
t/100_core/010_add_config.t
t/100_core/011_random_string.t
t/100_core/012_trigger_controller.t
t/100_core/013_tiffany.t

author/assets.pl  view on Meta::CPAN

sub register_js {
    my ($class, $method, $url, $name) = @_;

    no strict 'refs';
    *{__PACKAGE__ . '::' . $method} = sub {
        use strict;

        my $res = $ua->get($url);
        $res->is_success or die "Cannot fetch $url: " . $res->status_line;

        my $content = $res->decoded_content;
        open my $fh, '>:utf8', "lib/Amon2/Setup/Asset/${name}.pm";
        print {$fh} $xslate->render_string(<<'...', +{ file => $0, basename => basename($url), name => $name, data => Dumper({ 'js/' . basename($url) => $content})});
# This file is generated by <% file %>. Do not edit manually.
package Amon2::Setup::Asset::<% name %>;
use strict;
use warnings;

sub tags {
    <<',,,';
    <script src="<: uri_for('/static/js/<% basename %>') :>"></script>

author/assets.pl  view on Meta::CPAN

...
        close $fh;
    };
}

sub run_jquery {
    my $url = 'http://code.jquery.com/jquery-3.6.1.min.js';
    my $res = $ua->get($url);
    $res->is_success or die "Cannot fetch $url: " . $res->status_line;

    my $jquery = $res->decoded_content;
    open my $fh, '>:utf8', 'lib/Amon2/Setup/Asset/jQuery.pm';
    print {$fh} $xslate->render_string(<<'...', +{ file => $0, basename => basename($url), data => Dumper({ 'js/' . basename($url) => $jquery})});
# This file is generated by <% file %>. Do not edit manually.
package Amon2::Setup::Asset::jQuery;
use strict;
use warnings;

sub tags {
    <<',,,';
    <script src="<: uri_for('/static/js/<% basename %>') :>"></script>

author/assets.pl  view on Meta::CPAN


1;
...
    close $fh;
}

sub fetch {
    my $url = shift;
    my $res = $ua->get($url);
    $res->is_success or die "Cannot fetch $url: " . $res->status_line;
    return $res->decoded_content;
}

sub run_bootstrap {
    my $files = {};
    print "Fetching bootstrap\n";
    my $zip_url = 'https://github.com/twbs/bootstrap/archive/v4.4.1.zip';
    my $tmpdir = File::Temp::tempdir(CLEANUP => 1);
    my $tmp = "$tmpdir/bootstrap.zip";
    print "Saving files to $tmp\n";
    my $res = $ua->mirror($zip_url, $tmp);

lib/Amon2/Web/Request.pm  view on Meta::CPAN

    }
    return $self;
}

sub _encoding {
    my $self = shift;
    return $self->{_web_pkg} ? $self->{_web_pkg}->context->encoding : Amon2->context->encoding;
}

# ------------------------------------------------------------------------- 
# This object returns decoded parameter values by default

sub body_parameters {
    my ($self) = @_;
    $self->{'amon2.body_parameters'} ||= $self->_decode_parameters($self->SUPER::body_parameters());
}

sub query_parameters {
    my ($self) = @_;
    $self->{'amon2.query_parameters'} ||= $self->_decode_parameters($self->SUPER::query_parameters());
}

sub _decode_parameters {
    my ($self, $stuff) = @_;

    my $encoding = $self->_encoding();
    my @flatten = $stuff->flatten();
    my @decoded;
    while ( my ($k, $v) = splice @flatten, 0, 2 ) {
        push @decoded, Encode::decode($encoding, $k), Encode::decode($encoding, $v);
    }
    return Hash::MultiValue->new(@decoded);
}
sub parameters {
    my $self = shift;

    $self->env->{'amon2.request.merged'} ||= do {
        my $query = $self->query_parameters;
        my $body  = $self->body_parameters;
        Hash::MultiValue->new( $query->flatten, $body->flatten );
    };
}

lib/Amon2/Web/Request.pm  view on Meta::CPAN


Amon2::Web::Request - Amon2 Request Class

=head1 DESCRIPTION

This is a child class of L<Plack::Request>. Please see L<Plack::Request> for more details.

=head1 AUTOMATIC DECODING

This class decode query/body parameters automatically.
Return value of C<< $req->param() >>, C<< $req->body_parameters >>, etc. is the decoded value.

=head1 METHODS

=over 4

=item C<< $req->uri_with($args, $behavior) >>

Returns a rewritten URI object for the current request. Key/value pairs passed in will override existing parameters. You can remove an existing parameter by passing in an undef value. Unmodified pairs will be preserved.

You may also pass an optional second parameter that puts uri_with into append mode:

lib/Amon2/Web/Request.pm  view on Meta::CPAN

=item C<< $req->query_parameters_raw() >>

=item C<< $req->parameters_raw() >>

=item C<< $req->param_raw() >>

=item C<< $req->param_raw($key) >>

=item C<< $req->param_raw($key => $val) >>

These methods are the accessor to raw values. 'raw' means the value is not decoded.

=back

=cut

t/100_core/001_request_param_decoded.t  view on Meta::CPAN

    use parent qw/Amon2/;
}

my $c = MyApp::Web->bootstrap();

my $req = Amon2::Web::Request->new({
    QUERY_STRING   => 'foo=%E3%81%BB%E3%81%92&bar=%E3%81%B5%E3%81%8C1&bar=%E3%81%B5%E3%81%8C2',
    REQUEST_METHOD => 'GET',
});
subtest 'normal' => sub {
    ok Encode::is_utf8($req->param('foo')), 'decoded';
    ok Encode::is_utf8($req->query_parameters->{'foo'}), 'decoded';
    is $req->param('foo'), 'ほげ';
    is_deeply [$req->param('bar')], ['ふが1', 'ふが2'];
};
subtest 'accessor' => sub {
    ok !Encode::is_utf8($req->param_raw('foo')), 'not decoded';
    ok !Encode::is_utf8($req->parameters_raw->{'foo'}), 'not decoded';
};

done_testing;

t/300_setup/06_large.t  view on Meta::CPAN

        open my $fh, '>', $f;
        print $fh $buff;
        close $fh;
    }

    subtest 'test web' => sub {
        my $app = Plack::Util::load_psgi("script/my-app-web-server");
        my $mech = Test::WWW::Mechanize::PSGI->new(app => $app);
        my $res = $mech->get('http://localhost/');
        is($res->code, 200);
        like($res->decoded_content,qr(static/css/main.css\?t=\d{10}),'fuction static_file success');
    };

    subtest 'admin' => sub {
        my $app = Plack::Util::load_psgi("script/my-app-admin-server");
        my $mech = Test::WWW::Mechanize::PSGI->new(app => $app);
        {
            my $res = $mech->get('http://localhost/');
            is($res->code, 401);
        }
        {



( run in 0.335 second using v1.01-cache-2.11-cpan-26ccb49234f )