App::Hachero::Plugin::Analyze::URI - simple URI analyzer for App::Hachero


App-Hachero documentation Contained in the App-Hachero distribution.

Index


Code Index:

NAME

Top

App::Hachero::Plugin::Analyze::URI - simple URI analyzer for App::Hachero

SYNOPSYS

Top

  ---
  plugins:
    - module: Analyze::URI
      config:
        result_key: URI
        result:
            foo: path
            bar:
                query_form: keyword

DESCRIPTION

Top

implemented hooks

* analyze

AUTHOR

Top

Nobuo Danjou <nobuo.danjou@gmail.com>

SEE ALSO

Top

App::Hachero

App::Hachero::Result


App-Hachero documentation Contained in the App-Hachero distribution.

package App::Hachero::Plugin::Analyze::URI;
use strict;
use warnings;
use base qw(App::Hachero::Plugin::Base);
use URI::QueryParam;

sub initialize :Hook {
    my ($self, $context) = @_;
    my $config = $self->config->{config};
    $self->{result_key} = $config->{result_key} || 'URI';
    my @primary = keys %{$config->{result}};
    my $r = App::Hachero::Plugin::Analyze::URI::Result->new(
        {
            primary => @primary ? [ @primary ] : ['URI']
        }
    );
    $context->result->{$self->{result_key}} = $r;
}

sub analyze :Hook {
    my ($self, $context) = @_;
    my $req = $context->currentinfo->{request}->{uri} or return;
    my $hash = $self->config->{config}->{result};
    my $result = {};
    if (keys %$hash) {
        for my $key (keys %$hash) {
            my $meth = $hash->{$key};
            if (ref $meth eq 'HASH') {
                my ($meth, $param) = %$meth;
                $result->{$key} = $req->$meth($param);
            } else {
                $result->{$key} = $req->$meth;
            }
        }
    } else {
        $result->{URI} = $req->as_string;
    }
    $context->result->{$self->{result_key}}->push( $result );
}

package # hide from PAUSE
    App::Hachero::Plugin::Analyze::URI::Result;
use base qw(App::Hachero::Result::PrimaryPerInstance);

1;
__END__