Skip to content

Commit

Permalink
here are some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Apr 27, 2014
1 parent aaf3ee5 commit 9643f54
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@ Revision history for MetaCPAN-Client (previously MetaCPAN-API)
* Add proper POD fetching from module/file objects.
* GH #1: Switch from JSON.pm to JSON::MaybeXS.
* GH #2: Remove incorrect and unnecessary check for class names.
* Add some use-case examples (examples directory)

1.002000 24.04.14
* Add 'not' support for complex queries
Expand Down
1 change: 1 addition & 0 deletions examples/.#00-object.pl
19 changes: 19 additions & 0 deletions examples/author-country.pl
@@ -0,0 +1,19 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my @countries = qw<AT AU BE CA CH DE ES FR GB
IL IR IS NL PL RO RU UK US>;

my %cc2authors;

for my $cc ( @countries ) {
my $authors =
MetaCPAN::Client->new->author({ country => $cc });

$cc2authors{$cc} = $authors->total;
}

p %cc2authors;
18 changes: 18 additions & 0 deletions examples/author.pl
@@ -0,0 +1,18 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $author =
MetaCPAN::Client->new->author('XSAWYERX');

my %output = (
NAME => $author->name,
EMAILS => $author->email,
COUNTRY => $author->country,
CITY => $author->city,
PROFILE => $author->profile,
);

p %output;
16 changes: 16 additions & 0 deletions examples/author_releases.pl
@@ -0,0 +1,16 @@
use strict;
use warnings;
use DDP;
use MetaCPAN::Client;

my $mcpan = MetaCPAN::Client->new;

my $author = $mcpan->author('XSAWYERX');

my $releases = $author->releases;

p $releases->total;

while ( my $rel = $releases->next ) {
p $rel->name;
}
23 changes: 23 additions & 0 deletions examples/complex-either-and.pl
@@ -0,0 +1,23 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $authors =
MetaCPAN::Client->new->author({
either => [
{ name => 'Dave *' },
{ name => 'David *' },
],
all => [
{ email => '*gmail.com' }
],
});

my %output = (
TOTAL => $authors->total,
NAMES => [ map { $authors->next->name } 0 .. 9 ],
);

p %output;
20 changes: 20 additions & 0 deletions examples/complex-either-not.pl
@@ -0,0 +1,20 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $authors =
MetaCPAN::Client->new->author({
either => [
{ name => 'Dave *' },
{ name => 'David *' },
],
not => [
{ name => 'Dave C*' },
{ name => 'David M*' },
]
});

print "\n";
p ( $authors->total );
20 changes: 20 additions & 0 deletions examples/complex.pl
@@ -0,0 +1,20 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $authors =
MetaCPAN::Client->new->author({
either => [
{ name => 'Dave *' },
{ name => 'David *' },
]
});

my %output = (
TOTAL => $authors->total,
NAMES => [ map { $authors->next->name } 0 .. 9 ],
);

p %output;
15 changes: 15 additions & 0 deletions examples/distribution.pl
@@ -0,0 +1,15 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $dist =
MetaCPAN::Client->new->distribution('Moose');

my %output = (
NAME => $dist->name,
BUGS => $dist->bugs,
);

p %output;
18 changes: 18 additions & 0 deletions examples/release.pl
@@ -0,0 +1,18 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $release =
MetaCPAN::Client->new->release('Moo');

my %output = (
AUTHOR => $release->author,
DATE => $release->date,
STATUS => $release->status,
VERSION => $release->version,
TESTS => $release->tests,
);

p %output;
34 changes: 34 additions & 0 deletions examples/rev_deps-recursive.pl
@@ -0,0 +1,34 @@
use strict;
use warnings;
use Term::ANSIColor;

use MetaCPAN::Client;

$|=1;

my $dist = 'Hijk';

my $mcpan = MetaCPAN::Client->new;

print "\n\n", colored("* $dist", 'green'), "\n";
dig($dist,0);

sub dig {
my $dist = shift;
my $level = shift;

my $res = $mcpan->reverse_dependencies($dist);

for ( @$res ) {
if ( $level ) {
printf "%s%s\n",
colored('....'x$level, 'yellow'),
$_->distribution;
} else {
printf "\n>> %s\n",
colored($_->distribution, 'blue');
}

dig($_->distribution,$level+1);
}
};
18 changes: 18 additions & 0 deletions examples/rev_deps.pl
@@ -0,0 +1,18 @@
use strict;
use warnings;
use DDP;

use MetaCPAN::Client;

my $deps =
MetaCPAN::Client->new->rev_deps('Hijk');

my @output = (
map +{
name => $_->name,
author => $_->author
},
@{$deps}
);

p @output;

0 comments on commit 9643f54

Please sign in to comment.