App-AcmeCpanlists

 view release on metacpan or  search on metacpan

lib/App/AcmeCpanlists.pm  view on Meta::CPAN

    };

    # filter by query
    if (defined(my $q = $args{query})) {
        $q = lc($q);

        my @match_rows;
        my @exact_match_rows;
        my $type;
        for my $row (@rows) {
            my $summary = lc($row->{summary} // '');
            if (index($summary, $q) >= 0 ||
                (defined($row->{id}) && index(lc($row->{id}), $q) >= 0)) {
                my $rec = $row->{_ref};
                push @match_rows, $row;
                push @exact_match_rows, $row
                    if $summary eq $q ||
                        defined($row->{id}) && lc($row->{id}) eq $q;
            }
        }
        @rows = @match_rows;
        $resmeta->{'func.num_exact_matches'} = @exact_match_rows;
    }

    # remove detail if we forced detail earlier for matching against query
    if (!$args{detail} && $detail) {
        @rows = map { $_->{summary} } @rows;
    }

    [200, "OK", \@rows, $resmeta];
}

$SPEC{get_list} = {
    v => 1.1,
    summary => 'Get a CPAN list as raw data',
    args_rels => {
        %rels_filtering,
    },
    args => {
        %args_filtering,
        %arg_query,
    },
};
sub get_list {
    no strict 'refs';

    my %args = @_;

    my $res = list_lists(
        (map {(module=>$args{$_}) x !!defined($args{$_})}
             keys %args_filtering),
        query => $args{query},
        detail => 1,
        _with_ref => 1,
    );

    return $res unless $res->[0] == 200;

    my $rows = $res->[2];
    if (!@$rows) {
        return [404, "No such list"];
    } elsif ($res->[3]{'func.num_exact_matches'} == 1) {
        return [200, "OK", $rows->[0]{_ref}, {'func.type'=>$rows->[0]{type}}];
    } elsif (@$rows > 1) {
        return [300, "Multiple lists found (".~~@{$rows}."), please specify"];
    } else {
        return [200, "OK", $rows->[0]{_ref}, {'func.type'=>$rows->[0]{type}}];
    }
}

$SPEC{view_list} = {
    v => 1.1,
    summary => 'View a CPAN list as rendered POD',
    args_rels => {
        %rels_filtering,
    },
    args => {
        %args_filtering,
        %arg_query,
    },
};
sub view_list {
    require Pod::From::Acme::CPANLists;
    no strict 'refs';

    my %args = @_;

    my $res = get_list(%args);
    return $res unless $res->[0] == 200;

    my %podargs;
    if ($res->[3]{'func.type'} eq 'author') {
        $podargs{author_lists} = [$res->[2]];
        $podargs{module_lists} = [];
    } else {
        $podargs{author_lists} = [];
        $podargs{module_lists} = [$res->[2]];
    }
    my $podres = Pod::From::Acme::CPANLists::gen_pod_from_acme_cpanlists(
        %podargs);

    [200, "OK", $podres, {
        "cmdline.page_result"=>1,
        "cmdline.pager"=>"pod2man | man -l -"}];
}

sub _is_false { defined($_[0]) && !$_[0] }

$SPEC{list_entries_all} = {
    v => 1.1,
    summary => 'List entries from all installed CPAN lists',
    args_rels => {
        %rels_filtering,
    },
    args => {
        %args_filtering,
        %arg_query_opt,
        %arg_detail,
        %args_related_and_alternate,
    },
};



( run in 2.059 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )