Analysis/Listener/Example3.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 20 CC 1 SCAR 6.9
CC
1
Cov
0%
http_transaction
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Net::Analysis::Listener::Example3;
2 # $Id: Example3.pm 143 2005-11-03 17:36:58Z abworrall $
3  
4 use strict;
5 use warnings;
6 use base qw(Net::Analysis::Listener::Base);
7  
8 sub http_transaction {
9 my ($self, $args) = @_;
10 my ($req) = $args->{req}; # isa HTTP::Request
11 my ($req_mono) = $args->{req_mono}; # isa Net::Analysis::TCPMonologue
12 my ($resp_mono) = $args->{resp_mono}; # isa Net::Analysis::TCPMonologue
13  
14 # Print out time between sending last part of request, and receiving
15 # first part of response.
16 # (Note; these are Net::Analsysis::Time objects)
17 my ($network_wait_time) = $resp_mono->t_start() - $req_mono->t_end();
18 printf "%-50.50s: %8.2f\n", $req->uri(), $network_wait_time;
19 }
20  
21 1;
22  
23 =head1 NAME
24  
25 Net::Analysis::Listener::Example3 - looking at HTTP transactions
26  
27 =head1 SYNOPSIS
28  
29 package Net::Analysis::Listener::Example3;
30  
31 use strict;
32 use warnings;
33 use base qw(Net::Analysis::Listener::Base);
34  
35 sub http_transaction {
36 my ($self, $args) = @_;
37 my ($req) = $args->{req}; # isa HTTP::Request
38 my ($req_mono) = $args->{req_mono}; # isa Net::Analysis::TCPMonologue
39 my ($resp_mono) = $args->{resp_mono}; # isa Net::Analysis::TCPMonologue
40  
41 # Print out time between sending last part of request, and receiving
42 # first part of response.
43 # (Note; these are Net::Analsysis::Time objects)
44 my ($network_wait_time) = $resp_mono->t_start() - $req_mono->t_end();
45 printf "%-50.50s: %8.2f\n", $req->uri(), $network_wait_time;
46 }
47  
48 1;
49  
50 You can invoke this example on a TCP capture file from the command line, as
51 follows:
52  
53 $ perl -MNet::Analysis -e main HTTP Example3 t/t1_google.tcp
54  
55 Note the regex parameter being passed to the Example2 listener.
56  
57 =head1 DESCRIPTION
58  
59 How to sit on top of L<Net::Analysis::Listener::HTTP>. Note that you need to
60 load the HTTP listener as well as Example3 in the Perl command line ! If you
61 don't do this, then only the TCP listener will be loaded, no
62 C<http_transaction> events will be emitted, and so Example3 will listen in
63 vain.
64  
65 Other gotcahs; the C<t_start> and C<t_end> methods for TCPMonologue return
66 L<Net::Analysis::Time> objects, which while useful for certain things, might
67 not be what you want. You can turn them into floating point seconds easily
68 enough though.
69  
70 =head1 SEE ALSO
71  
72 L<Net::Analysis>,
73 L<Net::Analysis::Time>,
74 L<Net::Analysis::Listener::HTTP>.
75  
76 =head1 AUTHOR
77  
78 Adam B. Worrall, E<lt>worrall@cpan.orgE<gt>
79  
80 =head1 COPYRIGHT AND LICENSE
81  
82 Copyright (C) 2004 by Adam B. Worrall
83  
84 This library is free software; you can redistribute it and/or modify
85 it under the same terms as Perl itself, either Perl version 5.8.5 or,
86 at your option, any later version of Perl 5 you may have available.
87  
88 =cut