| 1 | package GitHub::Jobs; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | GitHub::Jobs - This module is a wrapper around the GitHub Jobs API. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Version 0.05 | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | Readonly my $BASE_URL => "http://jobs.github.com/positions.json"; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | type 'TrueFalse' => where { /\btrue\b|\bfalse\b/i }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 35 | 2 | has 'description' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 36 | 2 | has 'full_time' => ( is => 'rw', isa => 'TrueFalse' ); | |||||||||||||||||||||||||||
| 37 | 2 | has 'location' => ( is => 'ro', isa => 'Str' ); | |||||||||||||||||||||||||||
| 38 | 2 | has 'page' => ( is => 'ro', isa => 'Str' ); | |||||||||||||||||||||||||||
| 39 | 2 | has 'lat' => ( is => 'ro', isa => 'Str' ); | |||||||||||||||||||||||||||
| 40 | 2 | has 'long' => ( is => 'ro', isa => 'Str' ); | |||||||||||||||||||||||||||
| 41 | has 'browser' => ( | ||||||||||||||||||||||||||||
| 42 | is => 'rw', | ||||||||||||||||||||||||||||
| 43 | isa => 'LWP::UserAgent', | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | default => sub { return LWP::UserAgent->new(); } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | 2 | ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 48 | 0 | my $orig = shift; | |||||||||||||||||||||||||||
| 49 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( @_ == 1 && !ref $_[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and not ref $_[0]
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1
not ref $_[0]
Truth table0%0/3
A and not(B)
A= @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||
| 51 | 0 | return $class->$orig( description => $_[1] ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 0 | return $class->$orig(@_); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 2 | }; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 BUILD | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Check if description parameter is empty! | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | croak("ERROR: description must be specified.\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | unless ( $self->description ); | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head2 search | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Generate URL with parameters values and send HTTP Request! | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub search { | ||||||||||||||||||||||||||
|
Subroutine
search: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 0 | my ( $browser, $url, $request, $response, $content ); | |||||||||||||||||||||||||||
| 81 | 0 | $browser = $self->browser; | |||||||||||||||||||||||||||
| 82 | 0 | $url = sprintf( "%s?description=%s", $BASE_URL, $self->description ); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $url .= sprintf( "&full_time=%s", $self->full_time ) if $self->full_time; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $url .= sprintf( "&location=%s", $self->location ) if $self->location; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $url .= sprintf( "&lat=%s", $self->lat ) if $self->lat; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $url .= sprintf( "&long=%s", $self->long ) if $self->long; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $url .= sprintf( "&page=%s", $self->page ) if $self->page; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | $request = HTTP::Request->new( GET => $url ); | |||||||||||||||||||||||||||
| 89 | 0 | $response = $browser->request($request); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | croak( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | "ERROR: Couldn't fetch data [$url]:[" . $response->status_line . "]\n" ) | ||||||||||||||||||||||||||||
| 93 | unless $response->is_success; | ||||||||||||||||||||||||||||
| 94 | 0 | $content = $response->content; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | croak("ERROR: No data found.\n") unless defined $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | return $content; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 100 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 2 | ▶ | no Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | This module is the implementation of a interface to the GitHub Jobs API (as available on https://jobs.github.com/api) | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | use strict; | ||||||||||||||||||||||||||||
| 108 | use warnings; | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | use GitHub::Jobs; | ||||||||||||||||||||||||||||
| 111 | use JSON::XS; | ||||||||||||||||||||||||||||
| 112 | use POSIX; | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | $|++; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | my $query = 'software'; | ||||||||||||||||||||||||||||
| 117 | my $count = 0; | ||||||||||||||||||||||||||||
| 118 | my $pagination = 0; | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub initial { | ||||||||||||||||||||||||||||
| 121 | my $page = shift; | ||||||||||||||||||||||||||||
| 122 | my $str = GitHub::Jobs->new( description => $query, page => $page ); | ||||||||||||||||||||||||||||
| 123 | return JSON::XS::decode_json( $str->search() ); | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | sub decode { | ||||||||||||||||||||||||||||
| 127 | foreach my $items ( @{ initial($pagination) } ) { | ||||||||||||||||||||||||||||
| 128 | print $items->{title} . " ---- "; | ||||||||||||||||||||||||||||
| 129 | print $items->{company} . "\n"; | ||||||||||||||||||||||||||||
| 130 | $count++; | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | my $page_count = ceil( ( $count / 50 ) ); | ||||||||||||||||||||||||||||
| 133 | if ( ($page_count) && ( $page_count != $pagination ) ) { | ||||||||||||||||||||||||||||
| 134 | $pagination = $page_count; | ||||||||||||||||||||||||||||
| 135 | &decode; | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | decode; | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Ovidiu Nita Tatar, C<< <ovn.tatar at gmail.com> >> | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 BUGS | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Please report any bugs or feature requests to C<bug-github-jobs at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 148 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=GitHub-Jobs>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 149 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | or https://github.com/ovntatar/GitHub-Jobs/issues | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | perldoc GitHub::Jobs | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | https://github.com/ovntatar/GitHub-Jobs | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | You can also look for information at: | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =over 4 | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=GitHub-Jobs> | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | L<http://annocpan.org/dist/GitHub-Jobs> | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | L<http://cpanratings.perl.org/d/GitHub-Jobs> | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | L<http://search.cpan.org/dist/GitHub-Jobs/> | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =back | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Copyright 2013 Ovidiu Nita Tatar. | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 191 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 192 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =cut | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | 1; # End of GitHub::Jobs | |||||||||||||||||||||||||||