| 1 | # | ||||||||||||
| 2 | # This file is part of GitHub-API | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # This software is Copyright (c) 2013 by Chris Weyl. | ||||||||||||
| 5 | # | ||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||
| 7 | # | ||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||
| 9 | # | ||||||||||||
| 10 | package GitHub::API::Base; | ||||||||||||
| 11 | { | ||||||||||||
| 12 | 9 | $GitHub::API::Base::VERSION = '0.000000_03'; | |||||||||||
| 13 | } | ||||||||||||
| 14 | |||||||||||||
| 15 | 9 | ▶ | use common::sense; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 9 | ▶ | use autobox::JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | # ABSTRACT: Base class for GitHub::API classes | ||||||||||||
| 19 | |||||||||||||
| 20 | # debugging... | ||||||||||||
| 21 | #use Smart::Comments '###'; | ||||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub _get { | ||||||||||
|
Subroutine
_get: not called CC=2 SCAR=17.9
| |||||||||||||
| 24 | 0 | my $self = shift @_; | |||||||||||
| 25 | |||||||||||||
| 26 | ### fetching: $self->{base_url} . $self->{url} | ||||||||||||
| 27 | my $items = $self | ||||||||||||
| 28 | ->{ua} | ||||||||||||
| 29 | ->get( | ||||||||||||
| 30 | $self->{base_url} . $self->{url}, | ||||||||||||
| 31 | { headers => $self->{headers} }, | ||||||||||||
| 32 | ) | ||||||||||||
| 33 | ->{content} | ||||||||||||
| 34 | ->from_json | ||||||||||||
| 35 | 0 | ; | |||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | return ref $items eq 'ARRAY' ? $items : [ $items ]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 0 | ▶ | sub _post { | ||||||||||
|
Subroutine
_post: not called CC=2 SCAR=17.9
| |||||||||||||
| 41 | 0 | my ($self, $content, $path_part) = @_; | |||||||||||
| 42 | |||||||||||||
| 43 | 0 | my $url = $self->{base_url} . $self->{url}; | |||||||||||
| 44 | 0 | ▶ | $url .= $path_part // q{}; | ||||||||||
|
Condition0%0/2
$path_part // ""
MC/DC0%0/1
$path_part // ""
$path_part
Truth table0%0/2
A
A= $path_part
| |||||||||||||
| 45 | |||||||||||||
| 46 | ### POST to: $url | ||||||||||||
| 47 | #### $content | ||||||||||||
| 48 | my $resp = $self | ||||||||||||
| 49 | ->{ua} | ||||||||||||
| 50 | ->post($url, { content => $content->to_json, headers => $self->{headers} }) | ||||||||||||
| 51 | 0 | ; | |||||||||||
| 52 | |||||||||||||
| 53 | 0 | return $resp->{content}->from_json; | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 0 | ▶ | sub _delete { | ||||||||||
|
Subroutine
_delete: not called CC=2 SCAR=17.9
| |||||||||||||
| 57 | 0 | my ($self, $content, $path_part) = @_; | |||||||||||
| 58 | |||||||||||||
| 59 | 0 | my $url = $self->{base_url} . $self->{url}; | |||||||||||
| 60 | 0 | ▶ | $url .= $path_part // q{}; | ||||||||||
|
Condition0%0/2
$path_part // ""
MC/DC0%0/1
$path_part // ""
$path_part
Truth table0%0/2
A
A= $path_part
| |||||||||||||
| 61 | |||||||||||||
| 62 | ### DELETE to: $url | ||||||||||||
| 63 | my $resp = $self | ||||||||||||
| 64 | ->{ua} | ||||||||||||
| 65 | ->delete($url, { headers => $self->{headers} }) | ||||||||||||
| 66 | 0 | ; | |||||||||||
| 67 | |||||||||||||
| 68 | 0 | return $resp; | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | sub _next_append { | ||||||||||
|
Subroutine
_next_append: not called CC=1 SCAR=6.9
| |||||||||||||
| 72 | 0 | my ($self, $class, $url_append) = @_; | |||||||||||
| 73 | |||||||||||||
| 74 | 0 | my %thing = %$self; | |||||||||||
| 75 | 0 | $thing{url} .= $url_append; | |||||||||||
| 76 | |||||||||||||
| 77 | #### %thing | ||||||||||||
| 78 | 0 | return bless \%thing, $class; | |||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | sub _next { | ||||||||||
|
Subroutine
_next: not called CC=1 SCAR=6.9
| |||||||||||||
| 82 | 0 | my ($self, $class, $url) = @_; | |||||||||||
| 83 | |||||||||||||
| 84 | 0 | my %thing = %$self; | |||||||||||
| 85 | 0 | $thing{url} = $url; | |||||||||||
| 86 | |||||||||||||
| 87 | #### %thing | ||||||||||||
| 88 | 0 | return bless \%thing, $class; | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 9 | !!42; | |||||||||||
| 92 | |||||||||||||
| 93 | __END__ | ||||||||||||