291fd1ed45246bc8eea8bf6bec39f479100743c8
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Admin / Usage.pm
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
9 use Class::C3;
10
11 __PACKAGE__->mk_group_accessors('simple', 'synopsis', 'short_description');
12
13 sub prog_name {
14     Getopt::Long::Descriptive::prog_name();
15 }
16
17 sub set_simple {
18     my ($self,$field, $value) = @_;
19     my $prog_name = prog_name();
20     $value =~ s/%c/$prog_name/g;
21     $self->next::method($field, $value);
22 }
23
24
25 =head2 pod
26
27 This returns the usage formated as a pod document
28
29 =cut
30
31
32 sub pod {
33   my ($self) = @_;
34   return join qq{\n}, $self->pod_leader_text, $self->pod_option_text, $self->pod_authorlic_text;
35 }
36
37 sub pod_leader_text {
38   my ($self) = @_;
39
40   return qq{=head1 NAME\n\n}.prog_name()." - ".$self->short_description().qq{\n\n}.
41          qq{=head1 SYNOPSIS\n\n}.$self->leader_text().qq{\n}.$self->synopsis().qq{\n\n};
42
43 }
44
45 sub pod_authorlic_text {
46
47   return <<'EOA'
48 =head1 AUTHORS
49
50 See L<DBIx::Class/CONTRIBUTORS>
51
52 =head1 LICENSE
53
54 You may distribute this code under the same terms as Perl itself
55
56 =cut
57 EOA
58 }
59
60
61 sub pod_option_text {
62   my ($self) = @_;
63   my @options = @{ $self->{options} || [] };
64   my $string = q{};
65   return $string unless @options;
66
67   $string .= "=head1 OPTIONS\n\n=over\n\n";
68
69   foreach my $opt (@options) {
70     my $spec = $opt->{spec};
71     my $desc = $opt->{desc};
72     if ($desc eq 'spacer') {
73         $string .= "=back\n\n=head2 $spec\n\n=cut\n\n=over\n\n";
74         next;
75     }
76
77     $spec = Getopt::Long::Descriptive->_strip_assignment($spec);
78     $string .= "=item " . join " or ", map { length > 1 ? "B<--$_>" : "B<-$_>" }
79                              split /\|/, $spec; 
80     $string .= "\n\n$desc\n\n=cut\n\n";
81
82   }
83   $string .= "=back\n\n";
84   return $string;
85 }
86
87 1;