forked from loafle/openapi-generator-original
autodoc can analyse arbitrary classes
- added -c option to load and analyse any class
This commit is contained in:
parent
c097696276
commit
25c19135ff
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 <<HELP;
|
||||
Usage: autodoc [OPTION]
|
||||
|
||||
-w wide format (default)
|
||||
-n narrow format
|
||||
-p POD format
|
||||
-H HTML format
|
||||
-h print this help message
|
||||
|
||||
HELP
|
||||
|
||||
exit(0);
|
||||
if ($options{c}) {
|
||||
eval <<LOAD;
|
||||
use $my_app;
|
||||
apply_all_roles($my_app, "WWW::{{moduleName}}::Role::AutoDoc");
|
||||
LOAD
|
||||
die $@ if $@;
|
||||
}
|
||||
|
||||
else {
|
||||
package My::App;
|
||||
use Moose;
|
||||
with ('WWW::BookeoClient::Role', 'WWW::BookeoClient::Role::AutoDoc');
|
||||
with ('WWW::{{moduleName}}::Role', 'WWW::{{moduleName}}::Role::AutoDoc');
|
||||
}
|
||||
|
||||
package main;
|
||||
|
||||
@ -38,8 +32,9 @@ $opt = 'pod' if $options{p};
|
||||
$opt = 'wide' if $options{w};
|
||||
$opt = 'narrow' if $options{n};
|
||||
$opt = 'pod' if $options{H};
|
||||
$opt ||= 'wide';
|
||||
|
||||
my $api = My::App->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 <<HELP;
|
||||
Usage: autodoc [OPTION] [-c My::App::Class]
|
||||
|
||||
-w wide format (default)
|
||||
-n narrow format
|
||||
-p POD format
|
||||
-H HTML format
|
||||
-h print this help message
|
||||
-c your application class
|
||||
|
||||
HELP
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 <<HELP;
|
||||
Usage: autodoc [OPTION]
|
||||
|
||||
-w wide format (default)
|
||||
-n narrow format
|
||||
-p POD format
|
||||
-H HTML format
|
||||
-h print this help message
|
||||
|
||||
HELP
|
||||
|
||||
exit(0);
|
||||
if ($options{c}) {
|
||||
eval <<LOAD;
|
||||
use $my_app;
|
||||
apply_all_roles($my_app, "WWW::SwaggerClient::Role::AutoDoc");
|
||||
LOAD
|
||||
die $@ if $@;
|
||||
}
|
||||
|
||||
else {
|
||||
package My::App;
|
||||
use Moose;
|
||||
with ('WWW::BookeoClient::Role', 'WWW::BookeoClient::Role::AutoDoc');
|
||||
with ('WWW::SwaggerClient::Role', 'WWW::SwaggerClient::Role::AutoDoc');
|
||||
}
|
||||
|
||||
package main;
|
||||
|
||||
@ -38,8 +32,9 @@ $opt = 'pod' if $options{p};
|
||||
$opt = 'wide' if $options{w};
|
||||
$opt = 'narrow' if $options{n};
|
||||
$opt = 'pod' if $options{H};
|
||||
$opt ||= 'wide';
|
||||
|
||||
my $api = My::App->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 <<HELP;
|
||||
Usage: autodoc [OPTION] [-c My::App::Class]
|
||||
|
||||
-w wide format (default)
|
||||
-n narrow format
|
||||
-p POD format
|
||||
-H HTML format
|
||||
-h print this help message
|
||||
-c your application class
|
||||
|
||||
HELP
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user