Reindent lib/ and t/
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 19 Apr 2014 21:57:01 +0000 (00:57 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 19 Apr 2014 21:57:01 +0000 (00:57 +0300)
lib/WWW/Search/Torrentz.pm
lib/WWW/Search/Torrentz/Result.pm
t/WWW-Search-Torrentz-Result.t

index 4c575e64de34528dd17e6d52721829f1477ad54f..34ae025bf83ae5ec030ca1f1f3df087de805720e 100644 (file)
@@ -14,58 +14,58 @@ use WWW::Search::Torrentz::Result;
 sub gui_query{ shift->native_query(@_) }
 
 sub _native_setup_search{
-  my ($self, $native_query, $options) = @_;
-  $self->agent_email('marius@ieval.ro');
-  $options //= {};
-  my $base_url = $options->{search_url} // 'https://torrentz.eu/search';
-  $self->{search_debug} = $options->{search_debug};
-  $self->{_next_url} = "$base_url?f=$native_query";
-  $self->user_agent->delay(2/60);
+       my ($self, $native_query, $options) = @_;
+       $self->agent_email('marius@ieval.ro');
+       $options //= {};
+       my $base_url = $options->{search_url} // 'https://torrentz.eu/search';
+       $self->{search_debug} = $options->{search_debug};
+       $self->{_next_url} = "$base_url?f=$native_query";
+       $self->user_agent->delay(2/60);
 }
 
 sub _parse_tree{
-  my ($self, $tree) = @_;
-  my $found = 0;
-
-  my @potential_results = $tree->find('dl');
-  my $result_count = $tree->find('h2')->as_text;
-  if (defined $result_count && $result_count ne 'No Torrents Found') {
-       $result_count =~ s/orrents.*//;
-       $result_count =~ y/0-9//cd;
-       $self->approximate_result_count(int $result_count);
-  }
-
-  for my $node (@potential_results) {
-       my $a = $node->find('a');
-       next unless defined $a;
-
-       my $infohash = substr $a->attr('href'), 1;
-       next unless $infohash =~ m,^[a-f0-9]{40}$,;
-       my $title = $a->as_text;
-       my ($verified, $age, $size, $seeders, $leechers);
-       $verified = 0;
-       for my $span($node->find('span')) {
-         given($span->attr('class')){
-               $verified = int ($span->as_text =~ m,^\d+,) when 'v';
-               $age = $span->as_text when 'a';
-               $size = $span->as_text when 's';
-               $seeders = int $span->as_text when 'u';
-               $leechers = int $span->as_text when 'd';
-         }
+       my ($self, $tree) = @_;
+       my $found = 0;
+
+       my @potential_results = $tree->find('dl');
+       my $result_count = $tree->find('h2')->as_text;
+       if (defined $result_count && $result_count ne 'No Torrents Found') {
+               $result_count =~ s/orrents.*//;
+               $result_count =~ y/0-9//cd;
+               $self->approximate_result_count(int $result_count);
        }
 
-       push @{$self->{cache}}, WWW::Search::Torrentz::Result->new(infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers, ua => $self->user_agent);
-       say STDERR "infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug};
-       $found++;
-  }
-
-  my $url = $tree->look_down(rel => 'next');
-  if (defined $url) {
-       my $prev = $self->{_prev_url} =~ s,/[^/]+$,,r;
-       $self->{_next_url} = $prev . $url->attr('href')
-  }
-  say STDERR "Found: $found" if $self->{search_debug};
-  return $found;
+       for my $node (@potential_results) {
+               my $a = $node->find('a');
+               next unless defined $a;
+
+               my $infohash = substr $a->attr('href'), 1;
+               next unless $infohash =~ m,^[a-f0-9]{40}$,;
+               my $title = $a->as_text;
+               my ($verified, $age, $size, $seeders, $leechers);
+               $verified = 0;
+               for my $span ($node->find('span')) {
+                       given($span->attr('class')){
+                               $verified = int ($span->as_text =~ m,^\d+,) when 'v';
+                               $age = $span->as_text when 'a';
+                               $size = $span->as_text when 's';
+                               $seeders = int $span->as_text when 'u';
+                               $leechers = int $span->as_text when 'd';
+                       }
+               }
+
+               push @{$self->{cache}}, WWW::Search::Torrentz::Result->new(infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers, ua => $self->user_agent);
+               say STDERR "infohash => $infohash, title => $title, verified => $verified, age => $age, size => $size, seeders => $seeders, leechers => $leechers" if $self->{search_debug};
+               $found++;
+       }
+
+       my $url = $tree->look_down(rel => 'next');
+       if (defined $url) {
+               my $prev = $self->{_prev_url} =~ s,/[^/]+$,,r;
+               $self->{_next_url} = $prev . $url->attr('href')
+       }
+       say STDERR "Found: $found" if $self->{search_debug};
+       return $found;
 }
 
 1;
index 487e2026ca527c23e95770425079a8a6a5de1ebb..60aa726629a0f145c609e735f55534ecde7d8268 100644 (file)
@@ -11,15 +11,15 @@ use HTML::TreeBuilder;
 use URI::Escape qw/uri_escape/;
 
 sub new{
-  my ($class, %args) = @_;
-  my $self = $class->SUPER::new(@_);
-  $self->{parsed} = 0;
-
-  no strict 'refs';
-  $self->$_($args{$_}) for qw/title verified age size seeders leechers infohash/;
-  $self->{ua} = $args{ua};
-  $self->add_url("https://torrentz.eu/$args{infohash}");
-  $self
+       my ($class, %args) = @_;
+       my $self = $class->SUPER::new(@_);
+       $self->{parsed} = 0;
+
+       no strict 'refs';
+       $self->$_($args{$_}) for qw/title verified age size seeders leechers infohash/;
+       $self->{ua} = $args{ua};
+       $self->add_url("https://torrentz.eu/$args{infohash}");
+       $self
 }
 
 sub infohash { shift->_elem(infohash => @_) }
@@ -30,81 +30,81 @@ sub seeders { shift->_elem(seeders => @_) }
 sub leechers { shift->_elem(leechers => @_) }
 
 sub magnet{
-  my ($self, $full) = @_;
-  my $infohash = $self->infohash;
-  my $title = uri_escape $self->title;
-  my $uri = "magnet:?xt=urn:btih:$infohash&dn=$title";
+       my ($self, $full) = @_;
+       my $infohash = $self->infohash;
+       my $title = uri_escape $self->title;
+       my $uri = "magnet:?xt=urn:btih:$infohash&dn=$title";
 
-  $uri .= join '', map { "&tr=$_"} map { uri_escape $_ } $self->trackers if $full;
+       $uri .= join '', map { "&tr=$_"} map { uri_escape $_ } $self->trackers if $full;
 
-  $uri
+       $uri
 }
 
 sub parse_page {
-  my $self = $_[0];
-  my $tree = HTML::TreeBuilder->new;
-  $tree->utf8_mode(1);
-  $tree->parse($self->{ua}->get($self->url)->content);
-  $tree->eof;
-
-  my $trackers = $tree->look_down(class => 'trackers');
-  $self->{trackers} //= [];
-  for my $tracker ($trackers->find('dl')) {
-       push $self->{trackers}, $tracker->find('a')->as_text;
-  }
-
-  my $files = $tree->look_down(class => 'files');
-  $self->{files} //= [];
-  $self->parse_directory(scalar $files->find('li'), '');
-
-  $self->{parsed} = 1;
+       my $self = $_[0];
+       my $tree = HTML::TreeBuilder->new;
+       $tree->utf8_mode(1);
+       $tree->parse($self->{ua}->get($self->url)->content);
+       $tree->eof;
+
+       my $trackers = $tree->look_down(class => 'trackers');
+       $self->{trackers} //= [];
+       for my $tracker ($trackers->find('dl')) {
+               push $self->{trackers}, $tracker->find('a')->as_text;
+       }
+
+       my $files = $tree->look_down(class => 'files');
+       $self->{files} //= [];
+       $self->parse_directory(scalar $files->find('li'), '');
+
+       $self->{parsed} = 1;
 }
 
 sub parse_directory{
-  my ($self, $directory, $prefix) = @_;
-  $prefix .= $directory->as_text . '/';
-  my $contents_ul = $directory->right->find('ul');
-  return unless defined $contents_ul; # Empty directory
-  my @children = $contents_ul->content_list;
-  my $skip = 0;
-  for my $child (@children) {
-       if ($skip) {
-         $skip = 0;
-         next;
-       }
-
-       if (defined $child->attr('class') && $child->attr('class') eq 't') {
-         $self->parse_directory($child, $prefix);
-         $skip = 1;
-       } else {
-         $child->objectify_text;
-         my ($filename, $size) = $child->find('~text');
-         push $self->{files}, +{
-               path => $prefix.$filename->attr('text'),
-               size => $size->attr('text')
-         }
+       my ($self, $directory, $prefix) = @_;
+       $prefix .= $directory->as_text . '/';
+       my $contents_ul = $directory->right->find('ul');
+       return unless defined $contents_ul; # Empty directory
+       my @children = $contents_ul->content_list;
+       my $skip = 0;
+       for my $child (@children) {
+               if ($skip) {
+                       $skip = 0;
+                       next;
+               }
+
+               if (defined $child->attr('class') && $child->attr('class') eq 't') {
+                       $self->parse_directory($child, $prefix);
+                       $skip = 1;
+               } else {
+                       $child->objectify_text;
+                       my ($filename, $size) = $child->find('~text');
+                       push $self->{files}, +{
+                               path => $prefix.$filename->attr('text'),
+                               size => $size->attr('text')
+                       }
+               }
        }
-  }
 }
 
 sub trackers{
-  my $self = $_[0];
-  $self->parse_page unless $self->{parsed};
-  @{$self->{trackers}}
+       my $self = $_[0];
+       $self->parse_page unless $self->{parsed};
+       @{$self->{trackers}}
 }
 
 sub files{
-  my $self = $_[0];
-  $self->parse_page unless $self->{parsed};
-  @{$self->{files}}
+       my $self = $_[0];
+       $self->parse_page unless $self->{parsed};
+       @{$self->{files}}
 }
 
 sub torrent{
-  my $self = $_[0];
-  my $torrage = 'http://torrage.com/torrent/' . uc $self->infohash . '.torrent';
-  my $torrent = $self->{ua}->get($torrage)->content;
+       my $self = $_[0];
+       my $torrage = 'http://torrage.com/torrent/' . uc $self->infohash . '.torrent';
+       my $torrent = $self->{ua}->get($torrage)->content;
 
-  $torrent; # TODO: if this is undef, download metadata with magnet link
+       $torrent; # TODO: if this is undef, download metadata with magnet link
 }
 
 1;
index 1c98d8e578b24401c9ad782f9a83c4899dbd8411..cb3a1d4e5eab04a157f2165c58b6941a762c81ee 100644 (file)
@@ -6,13 +6,13 @@ use Test::More tests => 9;
 BEGIN { use_ok('WWW::Search::Torrentz::Result') };
 
 my $result = WWW::Search::Torrentz::Result->new(
-  title => 'Title',
-  verified => 4,
-  age => 'age',
-  size => 'size',
-  seeders => 50,
-  leechers => 50,
-  infohash => '514131e668a8134bca9668ef2e19e690924adf86',
+       title => 'Title',
+       verified => 4,
+       age => 'age',
+       size => 'size',
+       seeders => 50,
+       leechers => 50,
+       infohash => '514131e668a8134bca9668ef2e19e690924adf86',
 );
 
 is $result->title, 'Title', 'title';
This page took 0.019022 seconds and 4 git commands to generate.