File: GenClassPod.pm

package info (click to toggle)
libconfig-model-perl 2.155-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,172 kB
  • sloc: perl: 15,117; makefile: 19
file content (69 lines) | stat: -rw-r--r-- 1,948 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package Config::Model::Utils::GenClassPod;

# ABSTRACT: generate pod documentation from configuration models

use strict;
use warnings;
use 5.020;
use parent qw(Exporter);

use feature qw/postderef signatures/;
no warnings qw/experimental::postderef experimental::signatures/;

# function is used in one liner script, so auto export is easier to use
## no critic (Modules::ProhibitAutomaticExportation)
our @EXPORT = qw(gen_class_pod);

use Path::Tiny ;
use Config::Model ;             # to generate doc

sub gen_class_pod (@models) {
    # make sure that doc is generated from models from ./lib and not
    # installed models
    my $local_model_dir = path("lib/Config/Model/models") -> absolute;
    my $cm = Config::Model -> new(model_dir => $local_model_dir->stringify ) ;
    my %done;

    if (not scalar @models) {
        @models = map { /^\s*model\s*=\s*([\w:-]+)/ ? ($1) : (); }
        map  { $_->lines; }
        map  { $_->children; }
        path ("lib/Config/Model/")->children(qr/\.d$/);
    }

    foreach my $model (@models) {
        # %done avoid generating doc several times (generate_doc scan docs for
        # classes referenced by the model with config_class_name parameter)
        print "Checking doc for model $model\n";
        $cm->load($model) ;
        $cm->generate_doc ($model,'lib', \%done) ;
    }
    return;
}

1;

__END__

=head1 SYNOPSIS

 use Config::Model::Utils::GenClassPod;
 gen_class_pod;

 # or

 gen_class_pod('Foo','Bar',...)

=head1 DESCRIPTION

This module provides a single exported function: C<gen_class_pod>.

This function scans C<./lib/Config/Model/models/*.d>
and generate pod documentation for each file found there using
L<Config::Model::generate_doc|Config::Model/"generate_doc ( top_class_name , directory , [ \%done ] )">

You can also pass one or more class names. C<gen_class_pod> writes
the documentation for each passed class and all other classes used by
the passed classes.

=cut