| 1 | package WWW::Ohloh::API::StackEntry; | ||||||||||||||||||||
| 2 | 4 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | ▶ | use Object::InsideOut; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 4 | ▶ | use XML::LibXML; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 4 | ▶ | use Readonly; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 4 | ▶ | use List::MoreUtils qw/ any /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 4 | our $VERSION = '1.0_1'; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | my @ohloh_of : Field : Arg(ohloh); | |||||||||||||||||||
| 16 | 4 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||||||||||||
| 17 | 4 | my @xml_of : Field : Arg(xml); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 4 | my @api_fields = qw/ | |||||||||||||||||||
| 20 | id | ||||||||||||||||||||
| 21 | created_at | ||||||||||||||||||||
| 22 | stack_id | ||||||||||||||||||||
| 23 | project_id | ||||||||||||||||||||
| 24 | /; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | __PACKAGE__->create_field( '%' . $_, ":Set(_set_$_)", ":Get($_)" ) | ||||||||||||||||||||
| 27 | 4 | for @api_fields; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 4 | my @project : Field; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 344 | ▶ | sub _init : Init { | ||||||||||||||||||
|
Subroutine
_init: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 34 | 344 | my $self = shift; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 344 | ▶ | my $dom = $xml_of[$$self] or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 344 | for my $f (@api_fields) { | |||||||||||||||||||
| 39 | 1376 | my $method = "_set_$f"; | |||||||||||||||||||
| 40 | 1376 | $self->$method( $dom->findvalue("$f/text()") ); | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 344 | ▶ | if ( my ($project_xml) = $dom->findnodes('//project[1]') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 35 | $project[$$self] = WWW::Ohloh::API::Project->new( | |||||||||||||||||||
| 45 | ohloh => $ohloh_of[$$self], | ||||||||||||||||||||
| 46 | xml => $project_xml, | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 344 | return; | |||||||||||||||||||
| 51 | 4 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 309 | ▶ | sub as_xml { | ||||||||||||||||||
|
Subroutine
as_xml: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 56 | 309 | my $self = shift; | |||||||||||||||||||
| 57 | 309 | my $xml; | |||||||||||||||||||
| 58 | 309 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 309 | $w->startTag('stack_entry'); | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 309 | for my $f (@api_fields) { | |||||||||||||||||||
| 63 | 1236 | $w->dataElement( $f => $self->$f ); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 309 | ▶ | if ( my $project = $project[$$self] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 0 | $xml .= $project->as_xml; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 309 | $w->endTag; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 309 | return $xml; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 309 | ▶ | sub project { | ||||||||||||||||||
|
Subroutine
project: called CC=4 SCAR=17.2
Pod
documented
| |||||||||||||||||||||
| 78 | 309 | my $self = shift; | |||||||||||||||||||
| 79 | 309 | my $retrieve = shift; | |||||||||||||||||||
| 80 | 309 | ▶ | $retrieve = 1 unless defined $retrieve; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 309 | ▶ | if ($retrieve) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | ▶ | $project[$$self] ||= | ||||||||||||||||||
|
Condition0%0/3
$project[$$self] ||= $ohloh_of[$$self]->get_project($self->project_id)
MC/DC0%0/2
$project[$$self] ||= $ohloh_of[$$self]->get_project($self->project_id)
$project[$$self]
$ohloh_of[$$self]->get_project($self->project_id)
Truth table0%0/3
A ||= B
A= $project[$$self]B= $ohloh_of[$$self]->get_project($self->project_id)
| |||||||||||||||||||||
| 84 | $ohloh_of[$$self]->get_project( $self->project_id ); | ||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 309 | return $project[$$self]; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 4 | 'end of WWW::Ohloh::API::StackEntry'; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||