File Coverage

blib/lib/Business/BR/CNJ/NumberExtractor.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Business::BR::CNJ::NumberExtractor;
2              
3 1     1   72458 use strict;
  1         3  
  1         35  
4 1     1   832 use utf8;
  1         19  
  1         8  
5 1     1   47 use Exporter 'import';
  1         4  
  1         46  
6 1     1   212 use Business::BR::CNJ;
  0            
  0            
7              
8             our $VERSION = 0.03;
9             our @EXPORT_OK = qw/ cnj_extract_numbers cnj_extract_numbers_lwp /;
10              
11             sub cnj_extract_numbers {
12             my $txt = shift;
13              
14             my @n = $txt =~ m|(\d{7}.?\d{2}.?\d{4}.?\d.?\d{2}.?\d{4})|g;
15              
16             # Hard check and return
17             return map { ( Business::BR::CNJ::cnj_check_number($_) ? ($_) : () ) } @n;
18             }
19              
20             sub cnj_extract_lwp {
21             require LWP::UserAgent;
22             require Mojo::DOM;
23              
24             my $req = LWP::UserAgent->new()->get( @_ );
25              
26             die $req->status_line if !$req->is_success;
27              
28             # text/html
29             if ( $req->header( 'Content-type' ) eq 'text/html' ) {
30             my $dom = Mojo::DOM->new( $req->decoded_content );
31              
32             return cnj_extract_numbers( $dom->all_text );
33              
34             # Everything else
35             } else {
36             return cnj_extract_numbers( $req->decoded_content );
37             }
38              
39             }
40              
41             1;
42              
43             __END__