Skip to content

Commit

Permalink
initial committ
Browse files Browse the repository at this point in the history
  • Loading branch information
friedo committed Dec 3, 2011
0 parents commit f7f5ac7
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dist.ini
@@ -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]
97 changes: 97 additions & 0 deletions lib/Pod/Weaver/Section/Consumes.pm
@@ -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.

0 comments on commit f7f5ac7

Please sign in to comment.