root/library/perl/trunk/Parse-Apache-ServerStatus-Extended/lib/Parse/Apache/ServerStatus/Extended.pm

Revision 408, 4.2 kB (checked in by miya, 1 year ago)

Parse::Apache::ServerStatus::Extended: fix t/perlcritic.t.

Line 
1 package Parse::Apache::ServerStatus::Extended;
2
3 use warnings;
4 use strict;
5 use Web::Scraper;
6 use base qw( Parse::Apache::ServerStatus );
7
8 our $VERSION = '0.02';
9 use 5.8.1;
10
11 sub parse {
12     my $self    = shift;
13     my $content = $_[0] ? shift : $self->{content};
14     return $self->_raise_error('no content received') unless $content;
15
16     my $table = scraper {
17         process 'table[border="0"] tr',
18             'rows[]' => scraper {
19                 process 'td',
20                     'values[]' => 'TEXT';
21             }
22     };
23
24     my @scraped;
25     for ( @{ $table->scrape($content)->{rows} } ) {
26         next unless $_->{values};
27         my $stat = $_->{values};
28         push @scraped, {
29             srv     => $stat->[0],
30             pid     => $stat->[1],
31             acc     => $stat->[2],
32             m       => $stat->[3],
33             cpu     => $stat->[4],
34             ss      => $stat->[5],
35             req     => $stat->[6],
36             conn    => $stat->[7],
37             child   => $stat->[8],
38             slot    => $stat->[9],
39             client  => $stat->[10],
40             vhost   => $stat->[11],
41             request => $stat->[12],
42         };
43     }
44
45     return \@scraped;
46 }
47
48 1;
49 __END__
50
51 =head1 NAME
52
53 Parse::Apache::ServerStatus::Extended - Simple module to parse apache's extended server-status.
54
55
56 =head1 SYNOPSIS
57
58     use Parse::Apache::ServerStatus::Extended;
59
60     my $parser = Parse::Apache::ServerStatus::Extended->new;
61
62     $parser->request(
63        url     => 'http://localhost/server-status',
64        timeout => 30
65     ) or die $parser->errstr;
66
67     my $stat = $parser->parse or die $parser->errstr;
68
69     # or both in one step
70
71     my $stats = $parser->get(
72        url     => 'http://localhost/server-status',
73        timeout => 30
74     ) or die $parser->errstr;
75
76
77 =head1 DESCRIPTION
78
79 This module parses the content of apache's extended server-status.It works nicely with
80 apache versions 1.3 and 2.x.
81
82 =head1 METHODS
83
84 =head2 new()
85
86 Call C<new()> to create a new Parse::Apache::ServerStatus::Extended object.
87
88 =head2 request()
89
90 This method accepts one or two arguments: C<url> and C<timeout>. It requests the url
91 and safes the content into the object. The option C<timeout> is set to 180 seconds if
92 it is not set.
93
94 =head2 parse()
95
96 Call C<parse()> to parse the extended server status. This method returns an array reference with
97 the parsed content.
98
99 It's possible to call C<parse()> with the content as an argument.
100
101     my $stat = $prs->parse($content);
102
103 If no argument is passed then C<parse()> looks into the object for the content that is
104 stored by C<request()>.
105
106 =head2 get()
107
108 Call C<get()> to C<request()> and C<parse()> in one step. It accepts the same options like
109 C<request()> and returns the array reference that is returned by C<parse()>.
110
111 =head1 SEE ALSO
112
113 L<Parse::Apache::ServerStatus>
114
115 =head1 AUTHOR
116
117 Gosuke Miyashita  C<< <gosukenator at gmail.com> >>
118
119
120 =head1 LICENCE AND COPYRIGHT
121
122 This module is free software; you can redistribute it and/or
123 modify it under the same terms as Perl itself. See L<perlartistic>.
124
125
126 =head1 DISCLAIMER OF WARRANTY
127
128 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
129 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
130 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
131 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
132 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
133 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
134 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
135 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
136 NECESSARY SERVICING, REPAIR, OR CORRECTION.
137
138 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
139 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
140 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
141 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
142 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
143 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
144 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
145 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
146 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
147 SUCH DAMAGES.
148
Note: See TracBrowser for help on using the browser.