Client/Project.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« Client/Package.pm ↑ Summary Client/Roles/Client.pm »
1 # Copyright (c) 2015 SUSE LLC
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program (see the file COPYING); if not, write to the
14 # Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
16 #
17 package Net::OBS::Client::Project;
18  
19 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 0 ▶use XML::Structured;
Subroutine BEGIN: called CC=1 SCAR=2.6
21 use Carp;
22  
23 with 'Net::OBS::Client::Roles::BuildStatus';
24 with 'Net::OBS::Client::Roles::Client';
25  
26 =head1 NAME
27  
28 Net::OBS::Client::Project
29  
30 =head1 SYNOPSIS
31  
32 use Net::OBS::Client::Project;
33  
34 my $obj = Net::OBS::Client::Project->new(
35 apiurl => $apiurl,
36 name => $project,
37 use_oscrc => 0,
38 );
39  
40 my $res = $obj->fetch_resultlist(package => $package);
41  
42  
43 =head1 ATTRIBUTES
44  
45 =head2 resultlist
46  
47 =cut
48  
49 has resultlist => (
50 is => 'rw',
51 isa => 'HashRef',
52 lazy => 1,
53 default => \&fetch_resultlist,
54 );
55  
56 =head1 SUBROUTINES/METHODS
57  
58 =head2 fetch_resultlist - fetch build result code and other information for a project
59  
60 =cut
61  
62 # /build/OBS:Server:Unstable/_result
63 sub fetch_resultlist {
64 my ($self, %opts) = @_;
65  
66 my $api_path = '/build/'.$self->name.'/_result';
67 my @ext;
68  
69 while (my ($k,$v) = each %opts) { push @ext, "$k=$v"; }
70  
71 $api_path .= q{?} . join q{&}, @ext if @ext;
72 my $list = $self->request(GET=>$api_path);
73 my $data = XMLin($self->dtd->resultlist, $list);
74  
75 $self->resultlist($data);
76  
77 return $data;
78 }
79  
80 =head2 code - get current build result code
81  
82 my $code = $obj->code($repo, $arch);
83  
84 print "build succeeded\n" if ($code eq 'succeeded');
85  
86 =cut
87  
88 sub code {
89 my ($self, @args) = @_;
90 my $ra = $self->_get_repo_arch(@args);
91 return $ra->{code};
92 }
93  
94 =head2 dirty -
95  
96 my $dirty = $obj->dirty($repo, $arch);
97  
98 print "Project is in a clean state - no outstanding actions\n" if !$dirty;
99  
100 =cut
101  
102 sub dirty {
103 my ($self, @args) = @_;
104  
105 my $ra = $self->_get_repo_arch(@args);
106  
107 return ( exists $ra->{dirty} && $ra->{dirty} eq 'true' ) ? 1 : 0;
108 }
109  
110 sub _get_repo_arch {
111 my ($self, $repo, $arch) = @_;
112  
113 $self->repository($repo) if $repo;
114 $self->arch($arch) if $arch;
115  
116 croak("repository and arch needed to get code\n")
117 if ( !$self->repository || !$self->arch );
118  
119 foreach my $result ( @{$self->resultlist->{result}} ) {
120 return $result
121 if ( $result->{repository} eq $self->repository
122 && $result->{arch} eq $self->arch );
123 }
124  
125 croak("combination of repository and arch not found\n");
126 }
127  
128 __PACKAGE__->meta->make_immutable();
129  
130 =head1 AUTHOR
131  
132 Frank Schreiner, C<< <frank at samaxi.de> >>
133  
134 =head1 SEE ALSO
135  
136 You can find some examples in the L<contrib/> directory
137  
138  
139 =head1 COPYRIGHT
140  
141 Copyright 2016 Frank Schreiner <frank@samaxi.de>
142  
143 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
144  
145 =cut
146  
147 1;
« Client/Package.pm ↑ Summary Client/Roles/Client.pm »