CGI-Info

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

        serve_ai_summary();
    } else {
        serve_full_page();
    }

### API SPECIFICATION

#### Input

No arguments beyond the implicit object reference (`$self`).

    # Params::Validate::Strict schema -- no parameters
    {}

#### Output

    # Return::Set schema
    {
        type    => SCALAR,
        values  => [ 0, 1 ],
    }

Returns `1` if the visiting client is identified as an AI training or
inference crawler; `0` otherwise.

### MESSAGES

This method produces no log messages of its own.  Upstream callers such as
`is_robot()` may emit WAF warnings; see ["is\_robot"](#is_robot) for that table.

### PSEUDOCODE

    function is_ai(self):
        if self.{is_ai} is defined:
            return self.{is_ai}                    # instance-level cache

        if IS_AI environment variable is set:
            return self.{is_ai} = IS_AI ? 1 : 0   # override; no robot sync needed
                                                   # because is_robot() calls is_ai()

        ua     = HTTP_USER_AGENT
        remote = REMOTE_ADDR

        if not (remote and ua):
            return 0                               # not a CGI request; assume human

        if ua matches any AI_PAT token (case-insensitive):
            self.{is_robot} = 1                    # enforce is_ai => is_robot
            return self.{is_ai} = 1

        return self.{is_ai} = 0

## browser\_type

Returns a string classifying the visitor's client.  The possible values are:

- `'mobile'` -- smartphone or tablet (checked first)
- `'ai'` -- known AI training or inference crawler (see ["is\_ai"](#is_ai))
- `'search'` -- search-engine crawler
- `'robot'` -- other automated client
- `'web'` -- ordinary desktop or laptop browser

    use Carp;
    use Template;
    use CGI::Info;

    my $info = CGI::Info->new();
    my $dir  = $info->rootdir() . '/templates/' . $info->browser_type();

    my $filename = ref($info);
    $filename =~ s/::/\//g;
    $filename = "$dir/$filename.tmpl";

    (-f $filename && -r $filename)
        or croak "Cannot open template '$filename'";

    my $template = Template->new();
    $template->process($filename, {}) or croak $template->error();

## get\_cookie

Returns a cookie's value, or undef if no name is given, or the requested
cookie isn't in the jar.

Deprecated - use cookie() instead.

    use CGI::Info;

    my $i = CGI::Info->new();
    my $name = $i->get_cookie(cookie_name => 'name');
    print "Your name is $name\n";
    my $address = $i->get_cookie('address');
    print "Your address is $address\n";

## cookie

Returns a cookie's value, or undef if no name is given, or the requested
cookie isn't in the jar.
API is the same as "param",
it will replace the "get\_cookie" method in the future.

    use CGI::Info;

    my $name = CGI::Info->new()->cookie('name');
    print "Your name is $name\n";

### API SPECIFICATION

#### INPUT

    {
      cookie_name => {
        'type' => 'string',
        'min' => 1,
        'matches' => qr/^[!#-'*+\-.\^_`|~0-9A-Za-z]+$/    # RFC6265
      }
    }

#### OUTPUT

Cookie not set: `undef`



( run in 2.211 seconds using v1.01-cache-2.11-cpan-9789f410c06 )