From 25c19135ffb873b42efdce4926b17a6aede343ca Mon Sep 17 00:00:00 2001 From: Dave Baird Date: Thu, 12 Nov 2015 14:55:48 +0100 Subject: [PATCH] autodoc can analyse arbitrary classes - added -c option to load and analyse any class --- .../src/main/resources/perl/AutoDoc.mustache | 10 ++-- .../src/main/resources/perl/README.md | 5 +- .../src/main/resources/perl/Role.mustache | 5 +- .../resources/perl/autodoc.script.mustache | 57 ++++++++++++------- samples/client/petstore/perl/README.md | 5 +- samples/client/petstore/perl/bin/autodoc | 57 ++++++++++++------- .../perl/lib/WWW/SwaggerClient/Role.pm | 5 +- .../lib/WWW/SwaggerClient/Role/AutoDoc.pm | 10 ++-- 8 files changed, 96 insertions(+), 58 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/perl/AutoDoc.mustache b/modules/swagger-codegen/src/main/resources/perl/AutoDoc.mustache index b702c4a45f7..3817deb8911 100644 --- a/modules/swagger-codegen/src/main/resources/perl/AutoDoc.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/AutoDoc.mustache @@ -1,4 +1,4 @@ -package WWW::BookeoClient::Role::AutoDoc; +package WWW::{{moduleName}}::Role::AutoDoc; use List::MoreUtils qw(uniq); use Moose::Role; @@ -22,7 +22,7 @@ sub _printisa { my $super = join ', ', $meta->superclasses; my @roles = $meta->calculate_all_roles; - shift(@roles); # the first is a composite, the rest are the roles + #shift(@roles) if @roles > 1; # if > 1, the first is a composite, the rest are the roles my $isa = join ', ', grep {$_ ne $myclass} $meta->linearized_isa; my $sub = join ', ', $meta->subclasses; @@ -34,8 +34,8 @@ sub _printisa { write; foreach my $role (@roles) { - $rolepkg = $role->{package}; - next if $rolepkg eq 'WWW::BookeoClient::Role::AutoDoc'; + $rolepkg = $role->{package} || next; # some are anonymous, or something + next if $rolepkg eq 'WWW::{{moduleName}}::Role::AutoDoc'; $role_reqs = join ', ', keys %{$role->{required_methods}}; $role_reqs ||= ''; $~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES'; @@ -60,7 +60,7 @@ $myclass $sub . format ROLES = - Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ + Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~ $rolepkg requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~ $role_reqs diff --git a/modules/swagger-codegen/src/main/resources/perl/README.md b/modules/swagger-codegen/src/main/resources/perl/README.md index e3690f6f10b..7d0f62dca4b 100644 --- a/modules/swagger-codegen/src/main/resources/perl/README.md +++ b/modules/swagger-codegen/src/main/resources/perl/README.md @@ -186,8 +186,11 @@ output formats are supported: -p POD format -H HTML format -h print this help message + -c your application class + - +The `-c` option allows you to load and inspect your own application. A dummy +namespace is used if you don't supply your own class. # DOCUMENTATION FROM THE SWAGGER SPEC diff --git a/modules/swagger-codegen/src/main/resources/perl/Role.mustache b/modules/swagger-codegen/src/main/resources/perl/Role.mustache index 4f78850ae73..72c4b47390f 100644 --- a/modules/swagger-codegen/src/main/resources/perl/Role.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/Role.mustache @@ -269,7 +269,10 @@ output formats are supported: -p POD format -H HTML format -h print this help message - + -c your application class + +The C<-c> option allows you to load and inspect your own application. A dummy +namespace is used if you don't supply your own class. =head1 DOCUMENTATION FROM THE SWAGGER SPEC diff --git a/modules/swagger-codegen/src/main/resources/perl/autodoc.script.mustache b/modules/swagger-codegen/src/main/resources/perl/autodoc.script.mustache index 547aad21d9d..d669119c28b 100644 --- a/modules/swagger-codegen/src/main/resources/perl/autodoc.script.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/autodoc.script.mustache @@ -3,33 +3,27 @@ use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, '..', 'lib'); +use Moose::Util qw(apply_all_roles); use Getopt::Std; my %options=(); -getopts("wnphH", \%options); +getopts("wnphHc:", \%options); +help if $options{h}; -die "Too many options: there can be only one" if keys %options > 1; +my $my_app = $options{c} || 'My::App'; -$options{w}++ unless keys %options; - -if ($options{h}) { - print <new; +my $api = $my_app->new; if ($options{H}) { my $pod2html = "pod2html --backlink --css http://st.pimg.net/tucs/style.css?3"; @@ -52,3 +47,21 @@ else { } exit(0); + +# -------------------- +sub help { + print <catdir($FindBin::Bin, '..', 'lib'); +use Moose::Util qw(apply_all_roles); use Getopt::Std; my %options=(); -getopts("wnphH", \%options); +getopts("wnphHc:", \%options); +help if $options{h}; -die "Too many options: there can be only one" if keys %options > 1; +my $my_app = $options{c} || 'My::App'; -$options{w}++ unless keys %options; - -if ($options{h}) { - print <new; +my $api = $my_app->new; if ($options{H}) { my $pod2html = "pod2html --backlink --css http://st.pimg.net/tucs/style.css?3"; @@ -52,3 +47,21 @@ else { } exit(0); + +# -------------------- +sub help { + print < option allows you to load and inspect your own application. A dummy +namespace is used if you don't supply your own class. =head1 DOCUMENTATION FROM THE SWAGGER SPEC diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role/AutoDoc.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role/AutoDoc.pm index b702c4a45f7..333f5b4f626 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role/AutoDoc.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Role/AutoDoc.pm @@ -1,4 +1,4 @@ -package WWW::BookeoClient::Role::AutoDoc; +package WWW::SwaggerClient::Role::AutoDoc; use List::MoreUtils qw(uniq); use Moose::Role; @@ -22,7 +22,7 @@ sub _printisa { my $super = join ', ', $meta->superclasses; my @roles = $meta->calculate_all_roles; - shift(@roles); # the first is a composite, the rest are the roles + #shift(@roles) if @roles > 1; # if > 1, the first is a composite, the rest are the roles my $isa = join ', ', grep {$_ ne $myclass} $meta->linearized_isa; my $sub = join ', ', $meta->subclasses; @@ -34,8 +34,8 @@ sub _printisa { write; foreach my $role (@roles) { - $rolepkg = $role->{package}; - next if $rolepkg eq 'WWW::BookeoClient::Role::AutoDoc'; + $rolepkg = $role->{package} || next; # some are anonymous, or something + next if $rolepkg eq 'WWW::SwaggerClient::Role::AutoDoc'; $role_reqs = join ', ', keys %{$role->{required_methods}}; $role_reqs ||= ''; $~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES'; @@ -60,7 +60,7 @@ $myclass $sub . format ROLES = - Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ + Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~ $rolepkg requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~ $role_reqs