summary refs log tree commit diff
path: root/lib/MooseX/UserAgent/Config.pm
blob: 0b9beb462a9742b56cfe9cfcba0d85e9eb6bdd81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package MooseX::UserAgent::Config;

use Moose::Role;

has 'agent' => (
    isa     => 'Object',
    is      => 'rw',
    lazy    => 1,
    default => sub {
        my $self = shift;
        my $ua   = LWP::UserAgent->new;

        if (!$self->can('useragent_conf')) {
        }
        my $conf = $self->useragent_conf;
        $ua->agent( $conf->{name} ) if $conf->{name};
        $ua->from( $conf->{mail} )  if $conf->{mail};
        $ua->max_size( $conf->{max_size} ) if $conf->{max_size};
        $ua->timeout( $conf->{timeout}   || 180 );
        $ua;
    }
);

1;

__END__

=head1 NAME

RTGI::Role::UserAgent::Config

=head1 SYNOPSIS

    has useragent_conf => (
        isa     => 'HashRef',
        default => sub {
            {
                name     => 'myownbot',
                mail     => 'mail\@bot.com',
                timeout  => 60,
                max_size => 50000,
                cache    => {
                    use_cache => 1,
                    namespace => 'mybotua',
                    root      => '/tmp',
                }
            };
        }
    );

=head1 DESCRIPTION

=over 4

=item B<name>

UserAgent string used by the HTTP client. Default is to use the LWP or
AnyEvent::HTTP string. See L<LWP::UserAgent> or L<AnyEvent::HTTP>.

=item B<mail>

Mail string used by the HTTP client (only for LWP). Default is to use the
LWP string. See L<LWP::UserAgent>

=item B<max_size>

size limit for response content. The default is 3 000 000 octets. See
L<LWP::UserAgent>.

=item B<timeout>

Timeout value in seconds. The default timeout() value is 180 seconds

=item B<cache>

=over 2

=item B<use_cache>

Set to true to activate caching. Defaults is false.

=item B<root>

The location in the filesystem that will hold the root of the cache.

=item B<default_expires_in>

The default expiration time for objects place in the cache. Defaults to $EXPIRES_NEVER if not explicitly set.

=item B<namespace>

The namespace associated with this cache. Defaults to "Default" if not
explicitly set.

=back

=back

=head1 BUGS AND LIMITATIONS

=head1 AUTHOR

franck cuny  C<< <franck.cuny@rtgi.fr> >>

=head1 LICENCE AND COPYRIGHT

Copyright (c) 2009, RTGI
All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.