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 List::MoreUtils qw(uniq);
|
||||||
|
|
||||||
use Moose::Role;
|
use Moose::Role;
|
||||||
@ -22,7 +22,7 @@ sub _printisa {
|
|||||||
|
|
||||||
my $super = join ', ', $meta->superclasses;
|
my $super = join ', ', $meta->superclasses;
|
||||||
my @roles = $meta->calculate_all_roles;
|
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 $isa = join ', ', grep {$_ ne $myclass} $meta->linearized_isa;
|
||||||
my $sub = join ', ', $meta->subclasses;
|
my $sub = join ', ', $meta->subclasses;
|
||||||
@ -34,8 +34,8 @@ sub _printisa {
|
|||||||
write;
|
write;
|
||||||
|
|
||||||
foreach my $role (@roles) {
|
foreach my $role (@roles) {
|
||||||
$rolepkg = $role->{package};
|
$rolepkg = $role->{package} || next; # some are anonymous, or something
|
||||||
next if $rolepkg eq 'WWW::BookeoClient::Role::AutoDoc';
|
next if $rolepkg eq 'WWW::{{moduleName}}::Role::AutoDoc';
|
||||||
$role_reqs = join ', ', keys %{$role->{required_methods}};
|
$role_reqs = join ', ', keys %{$role->{required_methods}};
|
||||||
$role_reqs ||= '';
|
$role_reqs ||= '';
|
||||||
$~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES';
|
$~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES';
|
||||||
@ -60,7 +60,7 @@ $myclass
|
|||||||
$sub
|
$sub
|
||||||
.
|
.
|
||||||
format ROLES =
|
format ROLES =
|
||||||
Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
|
Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
|
||||||
$rolepkg
|
$rolepkg
|
||||||
requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
|
requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
|
||||||
$role_reqs
|
$role_reqs
|
||||||
|
@ -186,8 +186,11 @@ output formats are supported:
|
|||||||
-p POD format
|
-p POD format
|
||||||
-H HTML format
|
-H HTML format
|
||||||
-h print this help message
|
-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
|
# DOCUMENTATION FROM THE SWAGGER SPEC
|
||||||
|
|
||||||
|
@ -269,7 +269,10 @@ output formats are supported:
|
|||||||
-p POD format
|
-p POD format
|
||||||
-H HTML format
|
-H HTML format
|
||||||
-h print this help message
|
-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
|
=head1 DOCUMENTATION FROM THE SWAGGER SPEC
|
||||||
|
|
||||||
|
@ -3,33 +3,27 @@ use FindBin;
|
|||||||
use File::Spec;
|
use File::Spec;
|
||||||
use lib File::Spec->catdir($FindBin::Bin, '..', 'lib');
|
use lib File::Spec->catdir($FindBin::Bin, '..', 'lib');
|
||||||
|
|
||||||
|
use Moose::Util qw(apply_all_roles);
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
|
|
||||||
my %options=();
|
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{c}) {
|
||||||
|
eval <<LOAD;
|
||||||
if ($options{h}) {
|
use $my_app;
|
||||||
print <<HELP;
|
apply_all_roles($my_app, "WWW::{{moduleName}}::Role::AutoDoc");
|
||||||
Usage: autodoc [OPTION]
|
LOAD
|
||||||
|
die $@ if $@;
|
||||||
-w wide format (default)
|
}
|
||||||
-n narrow format
|
else {
|
||||||
-p POD format
|
package My::App;
|
||||||
-H HTML format
|
use Moose;
|
||||||
-h print this help message
|
with ('WWW::{{moduleName}}::Role', 'WWW::{{moduleName}}::Role::AutoDoc');
|
||||||
|
|
||||||
HELP
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
package My::App;
|
|
||||||
use Moose;
|
|
||||||
with ('WWW::BookeoClient::Role', 'WWW::BookeoClient::Role::AutoDoc');
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
@ -38,8 +32,9 @@ $opt = 'pod' if $options{p};
|
|||||||
$opt = 'wide' if $options{w};
|
$opt = 'wide' if $options{w};
|
||||||
$opt = 'narrow' if $options{n};
|
$opt = 'narrow' if $options{n};
|
||||||
$opt = 'pod' if $options{H};
|
$opt = 'pod' if $options{H};
|
||||||
|
$opt ||= 'wide';
|
||||||
|
|
||||||
my $api = My::App->new;
|
my $api = $my_app->new;
|
||||||
|
|
||||||
if ($options{H}) {
|
if ($options{H}) {
|
||||||
my $pod2html = "pod2html --backlink --css http://st.pimg.net/tucs/style.css?3";
|
my $pod2html = "pod2html --backlink --css http://st.pimg.net/tucs/style.css?3";
|
||||||
@ -52,3 +47,21 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
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
|
-p POD format
|
||||||
-H HTML format
|
-H HTML format
|
||||||
-h print this help message
|
-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
|
# DOCUMENTATION FROM THE SWAGGER SPEC
|
||||||
|
|
||||||
|
@ -3,33 +3,27 @@ use FindBin;
|
|||||||
use File::Spec;
|
use File::Spec;
|
||||||
use lib File::Spec->catdir($FindBin::Bin, '..', 'lib');
|
use lib File::Spec->catdir($FindBin::Bin, '..', 'lib');
|
||||||
|
|
||||||
|
use Moose::Util qw(apply_all_roles);
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
|
|
||||||
my %options=();
|
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{c}) {
|
||||||
|
eval <<LOAD;
|
||||||
if ($options{h}) {
|
use $my_app;
|
||||||
print <<HELP;
|
apply_all_roles($my_app, "WWW::SwaggerClient::Role::AutoDoc");
|
||||||
Usage: autodoc [OPTION]
|
LOAD
|
||||||
|
die $@ if $@;
|
||||||
-w wide format (default)
|
}
|
||||||
-n narrow format
|
else {
|
||||||
-p POD format
|
package My::App;
|
||||||
-H HTML format
|
use Moose;
|
||||||
-h print this help message
|
with ('WWW::SwaggerClient::Role', 'WWW::SwaggerClient::Role::AutoDoc');
|
||||||
|
|
||||||
HELP
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
package My::App;
|
|
||||||
use Moose;
|
|
||||||
with ('WWW::BookeoClient::Role', 'WWW::BookeoClient::Role::AutoDoc');
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
@ -38,8 +32,9 @@ $opt = 'pod' if $options{p};
|
|||||||
$opt = 'wide' if $options{w};
|
$opt = 'wide' if $options{w};
|
||||||
$opt = 'narrow' if $options{n};
|
$opt = 'narrow' if $options{n};
|
||||||
$opt = 'pod' if $options{H};
|
$opt = 'pod' if $options{H};
|
||||||
|
$opt ||= 'wide';
|
||||||
|
|
||||||
my $api = My::App->new;
|
my $api = $my_app->new;
|
||||||
|
|
||||||
if ($options{H}) {
|
if ($options{H}) {
|
||||||
my $pod2html = "pod2html --backlink --css http://st.pimg.net/tucs/style.css?3";
|
my $pod2html = "pod2html --backlink --css http://st.pimg.net/tucs/style.css?3";
|
||||||
@ -52,3 +47,21 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
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
|
-p POD format
|
||||||
-H HTML format
|
-H HTML format
|
||||||
-h print this help message
|
-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
|
=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 List::MoreUtils qw(uniq);
|
||||||
|
|
||||||
use Moose::Role;
|
use Moose::Role;
|
||||||
@ -22,7 +22,7 @@ sub _printisa {
|
|||||||
|
|
||||||
my $super = join ', ', $meta->superclasses;
|
my $super = join ', ', $meta->superclasses;
|
||||||
my @roles = $meta->calculate_all_roles;
|
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 $isa = join ', ', grep {$_ ne $myclass} $meta->linearized_isa;
|
||||||
my $sub = join ', ', $meta->subclasses;
|
my $sub = join ', ', $meta->subclasses;
|
||||||
@ -34,8 +34,8 @@ sub _printisa {
|
|||||||
write;
|
write;
|
||||||
|
|
||||||
foreach my $role (@roles) {
|
foreach my $role (@roles) {
|
||||||
$rolepkg = $role->{package};
|
$rolepkg = $role->{package} || next; # some are anonymous, or something
|
||||||
next if $rolepkg eq 'WWW::BookeoClient::Role::AutoDoc';
|
next if $rolepkg eq 'WWW::SwaggerClient::Role::AutoDoc';
|
||||||
$role_reqs = join ', ', keys %{$role->{required_methods}};
|
$role_reqs = join ', ', keys %{$role->{required_methods}};
|
||||||
$role_reqs ||= '';
|
$role_reqs ||= '';
|
||||||
$~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES';
|
$~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES';
|
||||||
@ -60,7 +60,7 @@ $myclass
|
|||||||
$sub
|
$sub
|
||||||
.
|
.
|
||||||
format ROLES =
|
format ROLES =
|
||||||
Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
|
Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
|
||||||
$rolepkg
|
$rolepkg
|
||||||
requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
|
requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
|
||||||
$role_reqs
|
$role_reqs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user