File Coverage

lib/Acme/MobileTradeFun/OldParser.pm
Criterion Covered Total %
statement 18 51 35.2
branch 0 14 0.0
condition 0 12 0.0
subroutine 6 8 75.0
pod 1 2 50.0
total 25 87 28.7


line stmt bran cond sub pod time code
1             package Acme::MobileTradeFun::OldParser;
2              
3 1     1   5 use strict;
  1         2  
  1         26  
4 1     1   3 use warnings;
  1         2  
  1         17  
5 1     1   5 use Mojo::DOM;
  1         1  
  1         18  
6 1     1   5 use Log::Log4perl qw/:easy/;
  1         1  
  1         6  
7 1     1   605 use URI::Encode qw/uri_decode/;
  1         2  
  1         35  
8 1     1   4 use Acme::MobileTradeFun::Utils;
  1         1  
  1         468  
9              
10             sub new {
11 0     0 0   my ( $class, $args ) = @_;
12 0           my $self = {};
13 0           $self->{ utils } = Acme::MobileTradeFun::Utils->new();
14 0           return bless $self, $class;
15             }
16              
17             =head2 parse_data
18              
19             parses HTML, populates $self->{ data } hash
20              
21             =cut
22              
23             sub parse_data {
24 0     0 1   my ( $self, $html, $all_cards ) = @_;
25              
26 0           my $card_found = 0;
27 0           my $dom = Mojo::DOM->new( $html );
28 0           my @new_cards;
29            
30 0           for my $table ( $dom->find( 'table.card_search_result_table' )->each ) {
31 0           my $category;
32              
33             # for each span in the table, I am looking for style attribute with
34             # color in it -- this should be the tag with category in it
35 0           for my $span ( $table->find( 'span' )->each ) {
36 0           my $color = $span->{ style };
37 0 0 0       $category = $span->text if ( $color && $color =~ /color/ );
38             }
39              
40 0           my @links = $table->find( 'a' )->each;
41 0           my $name = $links[0]->text;
42 0           my $rarity = $links[1]->text;
43 0           my $link = $links[2]->attr( 'href' );
44            
45 0 0 0       unless ( $category && $name && $rarity && $link ) {
      0        
      0        
46 0           my $message = "Something is missing:";
47 0 0         $message .= " $category" if ( $category );
48 0 0         $message .= " $name" if ( $name );
49 0 0         $message .= " $rarity" if ( $rarity );
50 0 0         $message .= " $link" if ( $link );
51 0           DEBUG $message;
52 0           next;
53             }
54            
55 0           my $url = uri_decode( $link );
56 0           my $card_name = "[$category]$name($rarity).jpg";
57 0           $card_name =~ s/\s+//g; # sometimes bunch of spaces creep in
58 0           $card_found++;
59              
60 0 0         if ( $self->{ utils }->is_new_card( $card_name, $all_cards ) ) {
61 0           my $elem = { name => $card_name, url => $url };
62 0           push @new_cards, $elem;
63             }
64             }
65 0           return ( $card_found, @new_cards );
66             }
67              
68             1;