FOAAS/Codegen.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.5
CC
2
Cov
0%
run
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package WebService::FOAAS::Codegen;
2  
3 use 5.014000;
4 use strict;
5 use warnings;
6  
7 use HTTP::Tiny;
8 use JSON::MaybeXS qw/decode_json/;
9  
10 our $VERSION = '0.002';
11  
12 sub run {
13 my $ht = HTTP::Tiny->new;
14 my $result = $ht->get('https://foaas.com/operations');
15 die $result->{reason} unless $result->{success};
16  
17 my @export;
18  
19 print <<"EOF";
20 ### Start of code generated by WebService::FOAAS::Codegen->run
21  
22 \=head1 AVAILABLE METHODS
23  
24 \=over
25 EOF
26  
27 my @ops = map { $_->{url} =~ y/-/_/r } @{decode_json $result->{content}};
28 for my $op (@ops) {
29 my (undef, $name, @args) = split '/', $op;
30 my $nargs = @args;
31 push @export, "foaas_$name";
32 print <<"EOF"
33  
34 \=item foaas_$name @{[join ', ', map { y/:/$/r } @args]}
35  
36 \=cut
37  
38 sub foaas_$name {
39 die "Expected $nargs arguments" unless \@_ == $nargs || \@_ == @{[$nargs + 1]};
40 request '$name', \@_;
41 }
42  
43 BEGIN { \*$name = \\&foaas_$name }
44 EOF
45 }
46  
47 my @export_ok = (@export, map { substr $_, 6 } @export);
48 print <<"EOF"
49  
50 BEGIN {
51 our \@EXPORT = qw/@export/;
52 our \@EXPORT_OK = qw/@export_ok/;
53 }
54  
55 \=back
56  
57 \=cut
58  
59 ### End of code generated by WebService::FOAAS::Codegen->run
60 EOF
61 }
62  
63 1;
64 __END__