File Coverage

blib/lib/MooseX/App/Meta/Role/Class/Documentation.pm
Criterion Covered Total %
statement 48 56 85.7
branch 9 14 64.2
condition 8 12 66.6
subroutine 14 16 87.5
pod 3 3 100.0
total 82 101 81.1


line stmt bran cond sub pod time code
1             # ============================================================================
2             package MooseX::App::Meta::Role::Class::Documentation;
3             # ============================================================================
4              
5 14     14   8618 use utf8;
  14         30  
  14         101  
6 14     14   690 use 5.010;
  14         43  
7              
8 14     14   65 use namespace::autoclean;
  14         21  
  14         93  
9 14     14   989 use Moose::Role;
  14         24  
  14         97  
10              
11 14     14   63915 use Pod::Elemental;
  14         6296859  
  14         138  
12 14     14   4951 use Pod::Elemental::Selectors qw();
  14         25  
  14         250  
13 14     14   62 use Pod::Elemental::Transformer::Pod5;
  14         22  
  14         324  
14 14     14   8939 use Pod::Elemental::Transformer::Nester;
  14         1149104  
  14         7651  
15              
16             has 'command_short_description' => (
17             is => 'rw',
18             isa => 'Maybe[Str]',
19             lazy => 1,
20             builder => '_build_command_short_description',
21             );
22              
23             has 'command_long_description' => (
24             is => 'rw',
25             isa => 'Maybe[Str]',
26             lazy => 1,
27             builder => '_build_command_long_description',
28             );
29              
30             has 'command_usage' => (
31             is => 'rw',
32             isa => 'Maybe[Str]',
33             lazy => 1,
34             builder => '_build_command_usage',
35             );
36              
37             has 'command_strict' => (
38             is => 'rw',
39             isa => 'Bool',
40             default => sub {0},
41             );
42              
43             sub command_short_description_predicate {
44 23     23 1 59 my ($self) = @_;
45 23         67 return $self->_command_pod_predicate('command_short_description');
46             }
47              
48             sub _build_command_short_description {
49 9     9   13 my ($self) = @_;
50 9         38 my %pod = $self->_build_command_pod();
51             return $pod{'command_short_description'}
52 9 100       138 if defined $pod{'command_short_description'};
53 6         200 return;
54             }
55              
56             sub command_long_description_predicate {
57 36     36 1 59 my ($self) = @_;
58 36         119 return $self->_command_pod_predicate('command_long_description');
59             }
60              
61             sub _build_command_long_description {
62 0     0   0 my ($self) = @_;
63 0         0 my %pod = $self->_build_command_pod();
64             return $pod{'command_long_description'}
65 0 0       0 if defined $pod{'command_long_description'};
66 0         0 return;
67             }
68              
69             sub command_usage_predicate {
70 35     35 1 68 my ($self) = @_;
71 35         174 return $self->_command_pod_predicate('command_usage');
72             }
73              
74             sub _build_command_usage {
75 0     0   0 my ($self) = @_;
76 0         0 my %pod = $self->_build_command_pod();
77             return $pod{'command_usage'}
78 0 0       0 if defined $pod{'command_usage'};
79 0         0 return;
80             }
81              
82             sub _command_pod_predicate {
83 94     94   155 my ($self,$field) = @_;
84              
85 94         387 my $attribute = $self->meta->find_attribute_by_name($field);
86              
87 94 100       5092 unless ($attribute->has_value($self)) {
88 14         578 $self->_build_command_pod($field);
89             }
90              
91 94         1861 my $value = $attribute->get_value($self);
92              
93 94 100 66     11392 return (defined $value && $value ? 1:0);
94             }
95              
96              
97             sub _build_command_pod {
98 23     23   41 my ($self) = @_;
99              
100 23         158 my %pod_raw = MooseX::App::Utils::parse_pod($self->name);
101              
102             my %pod = (
103             command_usage => ($pod_raw{SYNOPSIS} || $pod_raw{USAGE}),
104             command_long_description => ($pod_raw{DESCRIPTION} || $pod_raw{OVERVIEW}),
105 23   66     2819 command_short_description => ($pod_raw{NAME} || $pod_raw{ABSTRACT}),
      66        
      66        
106             );
107              
108             # Loop sections that need to be extracted from POD
109 23         82 foreach my $key (keys %pod) {
110 69         962 my $meta_attribute = $self->meta->find_attribute_by_name($key);
111             next
112 69 50       2719 unless defined $meta_attribute;
113             next
114 69 100       183 if $meta_attribute->has_value($self);
115 61         1197 $meta_attribute->set_raw_value($self,$pod{$key});
116             }
117              
118 23         429 return %pod;
119             }
120              
121             #{
122             # package Moose::Meta::Class::Custom::Trait::AppCommand;
123             # sub register_implementation { return 'MooseX::App::Meta::Role::Class::Documentation' }
124             #}
125              
126             1;
127              
128             __END__
129              
130             =pod
131              
132             =encoding utf8
133              
134             =head1 NAME
135              
136             MooseX::App::Meta::Role::Class::Documentation - Meta class role for command classes
137              
138             =head1 DESCRIPTION
139              
140             This meta class role will automatically be applied to all command classes.
141             This documentation is only of interest if you intend to write plugins for
142             MooseX::App.
143              
144             =head1 ACCESSORS
145              
146             =head2 command_short_description
147              
148             Read/set the short command description. Will be extracted from the Pod NAME
149             or ABSTRACT section if not set. Alternative this will be taken from the
150             DistZilla ABSTRACT tag.
151              
152             =head2 command_long_description
153              
154             Read/set the long command description. Will be extracted from the Pod
155             DESCRIPTION or OVERVIEW section if not set.
156              
157             =head2 command_usage
158              
159             Read/set the long command usage. Will be extracted from the Pod
160             SYNOPSIS or USAGE section if not set. If these Pod sections are not defined
161             the usage will be autogenerated.
162              
163             =head2 command_short_description_predicate
164              
165             Checks if command_short_description is available
166              
167             =head2 command_long_description_predicate
168              
169             Checks if command_long_description is available
170              
171             =head2 command_usage_predicate
172              
173             Checks if command_usage is available
174              
175             =head2 command_strict
176              
177             Read/set the strict command flag. If strict is enabled the command will
178             terminate with an error message if superfluous/unknown positional parameters
179             are supplied. If disabled all extra parameters will be copied to the
180             L<extra_argv> attribute.
181              
182             The app_strict function in the app classes allows one to set this option
183             globally.
184              
185             =head1 METHODS
186              
187             =head2 _build_command_pod
188              
189             Parses the Pod from the command class.
190              
191             =cut