Lint/UserAgent.pm

filter: Statementstmt 80.0% 20 / 25 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 75.6% 28 / 37 CC 4 SCAR 15.1
CC
4
Cov
72%
request
12.0
import
2.0
BEGIN
1.0
CRAP 4.5
« Lint.pm ↑ Summary
1 package HTTP::Lint::UserAgent;
2  
3 =head1 NAME
4  
5 HTTP::Lint::UserAgent - HTTP User agent that warns for suspicious transactions
6  
7 =head1 SYNOPSIS
8  
9 # Do not overload LWP::UserAgent::request;
10 use HTTP::Lint::UserAgent qw/:noinject/;
11 new HTTP::Lint::UserAgent->request ($request);
12  
13 # Do overload LWP::UserAgent::request;
14 use HTTP::Lint::UserAgent;
15 use LWP::UserAgent;
16 new LWP::UserAgent->request ($request);
17  
18 # Overload LWP::UserAgent::request without script modification;
19 perl -MHTTP::Lint::UserAgent client.pl
20  
21 =head1 DESCRIPTION
22  
23 L<HTTP::Lint::UserAgent> subclasses L<LWP::UserAgent>, providing
24 B<request> method that checks each transaction and messages involved
25 when it finishes with L<HTTP::Lint> and produces warning on console
26 (with B<warn>).
27  
28 Unless loaded with B<:noinject>, it replaces the B<request> method
29 in L<LWP::UserAgent> package, transparently intercepting all
30 requests.
31  
32 =cut
33  
34 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 ▶use HTTP::Lint qw/http_lint/;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use base qw/LWP::UserAgent/;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 sub request
41 0 ▶{
Subroutine request: not called CC=3 SCAR=24.8
Pod documented
42 0 my $response = lwp_request (@_);
43 0 ▶ if ($response) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response) 0 0 0
44 0 warn $_ foreach http_lint ($response)
45 }
46 0 return $response;
47 }
48  
49 sub import
50 1 ▶{
Subroutine import: called CC=2 SCAR=7.1
51 1 my $class = shift;
52 0 ▶ return if grep { $_ eq ':noinject' } @_;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq ":noinject";} @_ 0 1 1
53  
54 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 *HTTP::Lint::UserAgent::lwp_request = \&LWP::UserAgent::request;
56 1 *LWP::UserAgent::request = \&request;
57 }
58  
59 =head1 BUGS
60  
61 It's hackish, use it only for debugging and avoid
62 using it in production code!
63  
64 Not much can go wrong, but it's just not nice.
65  
66 =head1 SEE ALSO
67  
68 =over
69  
70 =item *
71  
72 L<LWP::UserAgent> -- The User Agent
73  
74 =item *
75  
76 L<HTTP::Lint> -- Checker module
77  
78 =back
79  
80 =head1 COPYRIGHT
81  
82 Copyright 2011, Lubomir Rintel
83  
84 This program is free software; you can redistribute it and/or modify it
85 under the same terms as Perl itself.
86  
87 =head1 AUTHOR
88  
89 Lubomir Rintel C<lkundrak@v3.sk>
90  
91 =cut
92  
93 1 1;
« Lint.pm ↑ Summary