Hi Mike,

On Fri, 09 May 2014 13:56:24 -0500
Mike Dunaway <ekimduna...@gmail.com> wrote:

> So, it's been a while since I've used Perl and I never really got THAT 
> deep into it to begin with, but I was reading over the source code for 
> MetaCPAN::Client: 
> http://api.metacpan.org/source/XSAWYERX/MetaCPAN-Client-1.003000/lib/MetaCPAN/Client.pm
>  
> and I was wondering where I could read more about basically everything 
> that's going on here:
> 

it's great that you are interested in Perl.

The following sites provide links to recommended and modern resources:

* http://perl-tutorial.org/ 

* http://perl-begin.org/ (*note:* I originated and am maintaining it).

Perhaps I'll try to explain some of the stuff that is going on in the
subroutine you quoted.

> sub _reverse_deps {
>      my $self = shift;
>      my $dist = shift;

This declares a subroutine called _reverse_deps and extracts two arguments -
$self and $dist. $self is a convention for the class' instance (= the object on
which the method is acting).

> 
>      my $res;
> 

Declares a variable called $res.

>      eval {

eval { traps exceptions.

>          $res = $self->fetch(
>              '/search/reverse_dependencies/'.$dist,
>              {
>                  query  => { match_all => {} },
>                  filter => { term => { 'release.status' => 'latest' } },
>                  size   => 5000,
>              }
>          );

Calls the ->fetch() subroutine on the $self object, with a URL that is a
concatenation, and a nested hash (of hashes and strings). See:

http://perl-begin.org/topics/references/

> 
>      } or do {
>          warn $@;
>          return [];
>      };

If the eval returns false, just warn the exception (in $@) and return an empty
[]. do is used to group several commands (without trapping exceptions and it
also has some magic with statement modifiers like trailing while).

> 
>      return +[
>          map { MetaCPAN::Client::Release->new_from_request($_->{'_source'}) }
>          @{ $res->{'hits'}{'hits'} }
>      ];

returns an array reference containing a mapping of a $res subscript while
initialising each entry's '_source' key into an object of
MetaCPAN::Client::Release.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Perl Humour - http://perl-begin.org/humour/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.
    — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to