Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f7f5ac7
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name = Pod-Weaver-Section-Consumes | ||
author = Mike Friedman <friedo@friedo.com> | ||
license = Perl_5 | ||
copyright_holder = Mike Friedman | ||
copyright_year = 2011 | ||
|
||
version = 0.001 | ||
|
||
[@Basic] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package Pod::Weaver::Section::Consumes; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
|
||
# ABSTRACT: Add a list of roles to your POD. | ||
|
||
use Moose; | ||
with 'Pod::Weaver::Role::Section'; | ||
|
||
use aliased 'Pod::Elemental::Element::Nested'; | ||
use aliased 'Pod::Elemental::Element::Pod5::Command'; | ||
|
||
sub weave_section { | ||
my ( $self, $doc, $input ) = @_; | ||
|
||
my $file = $input->{filename}; | ||
return unless $file =~ m{^lib/}; | ||
|
||
# yeah, this is a stupid way to do it. it's only for generating | ||
# docs though. shut up. | ||
my $success = do $file; | ||
|
||
die "Could not compile $file to find role data: $@ $!" | ||
unless $success; | ||
|
||
my $module = $file; | ||
$module =~ s{^lib/}{}; # assume modules live under lib | ||
$module =~ s{/}{::}g; | ||
$module =~ s/\.pm//; | ||
|
||
return unless $module->can( 'meta' ); | ||
|
||
my @roles = $self->_get_roles( $module ); | ||
|
||
return unless @roles; | ||
|
||
my @pod = ( | ||
Command->new( { | ||
command => 'over', | ||
content => 4 | ||
} ), | ||
|
||
map { | ||
Command->new( { | ||
command => 'item', | ||
content => sprintf 'L<%s>', $_->name | ||
} ), | ||
} @roles | ||
); | ||
|
||
push @{ $doc->children }, | ||
Nested->new( { | ||
type => 'command', | ||
command => 'head1', | ||
content => 'CONSUMES', | ||
children => \@pod | ||
} ); | ||
|
||
} | ||
|
||
sub _get_roles { | ||
my ( $self, $module ) = @_; | ||
|
||
my @roles = $module->meta->calculate_all_roles; | ||
|
||
use Data::Dumper; | ||
print Dumper \@roles; | ||
|
||
return @roles; | ||
} | ||
|
||
|
||
1; | ||
|
||
|
||
=pod | ||
=head1 SYNOPSIS | ||
In your C<weaver.ini>: | ||
[Consumes] | ||
=head1 DESCRIPTION | ||
This L<Pod::Weaver> section plugin creates a "CONSUMES" section in your POD | ||
which will contain a list of all the roles consumed by your class. It accomplishes | ||
this by attempting to compile your class and interrogating its metaclass object. | ||
Classes which do not have a C<meta> method will be skipped. | ||