Commit | Line | Data |
a6c29f38 |
1 | package # hide from PAUSE |
2 | DBIx::Class::Admin::Usage; |
3 | |
4 | |
5 | use base 'Getopt::Long::Descriptive::Usage'; |
6 | |
7 | use base 'Class::Accessor::Grouped'; |
8 | |
a6c29f38 |
9 | __PACKAGE__->mk_group_accessors('simple', 'synopsis', 'short_description'); |
10 | |
11 | sub prog_name { |
12 | Getopt::Long::Descriptive::prog_name(); |
13 | } |
14 | |
15 | sub set_simple { |
16 | my ($self,$field, $value) = @_; |
17 | my $prog_name = prog_name(); |
18 | $value =~ s/%c/$prog_name/g; |
19 | $self->next::method($field, $value); |
20 | } |
21 | |
22 | |
a6c29f38 |
23 | |
a7982681 |
24 | # This returns the usage formated as a pod document |
a6c29f38 |
25 | sub pod { |
26 | my ($self) = @_; |
fd576c43 |
27 | return join qq{\n}, $self->pod_leader_text, $self->pod_option_text, $self->pod_authorlic_text; |
a6c29f38 |
28 | } |
29 | |
30 | sub pod_leader_text { |
31 | my ($self) = @_; |
32 | |
33 | return qq{=head1 NAME\n\n}.prog_name()." - ".$self->short_description().qq{\n\n}. |
34 | qq{=head1 SYNOPSIS\n\n}.$self->leader_text().qq{\n}.$self->synopsis().qq{\n\n}; |
35 | |
36 | } |
37 | |
fd576c43 |
38 | sub pod_authorlic_text { |
39 | |
a7982681 |
40 | return join ("\n\n", |
41 | '=head1 AUTHORS', |
42 | 'See L<DBIx::Class/CONTRIBUTORS>', |
43 | '=head1 LICENSE', |
44 | 'You may distribute this code under the same terms as Perl itself', |
45 | '=cut', |
46 | ); |
fd576c43 |
47 | } |
48 | |
a6c29f38 |
49 | |
50 | sub pod_option_text { |
51 | my ($self) = @_; |
52 | my @options = @{ $self->{options} || [] }; |
53 | my $string = q{}; |
54 | return $string unless @options; |
55 | |
56 | $string .= "=head1 OPTIONS\n\n=over\n\n"; |
57 | |
58 | foreach my $opt (@options) { |
59 | my $spec = $opt->{spec}; |
60 | my $desc = $opt->{desc}; |
7901452a |
61 | next if ($desc eq 'hidden'); |
a6c29f38 |
62 | if ($desc eq 'spacer') { |
63 | $string .= "=back\n\n=head2 $spec\n\n=cut\n\n=over\n\n"; |
64 | next; |
65 | } |
66 | |
67 | $spec = Getopt::Long::Descriptive->_strip_assignment($spec); |
68 | $string .= "=item " . join " or ", map { length > 1 ? "B<--$_>" : "B<-$_>" } |
8273e845 |
69 | split /\|/, $spec; |
a6c29f38 |
70 | $string .= "\n\n$desc\n\n=cut\n\n"; |
71 | |
72 | } |
73 | $string .= "=back\n\n"; |
74 | return $string; |
75 | } |
76 | |
77 | 1; |