« lib/Meta/Grapher/Moose/Role/HasOutput.pm
↑ Summary
lib/Meta/Grapher/Moose/Renderer/Plantuml/Class.pm »
| 1 | package Meta::Grapher::Moose::CommandLine; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use namespace::autoclean; | ||
| 6 | |||
| 7 | our $VERSION = '1.03'; | ||
| 8 | |||
| 9 | # This globally changes the underlying Getopt::Long behavior to allow passing | ||
| 10 | # through of unprocessed dash arguments without error, which allows us to have | ||
| 11 | # multiple classes to have an attempt to read the file. Ideally this wouldn't | ||
| 12 | # be a global setting, but the conclusion of #moose is that this is good | ||
| 13 | # enough | ||
| 14 | use Getopt::Long qw(:config pass_through); | ||
| 15 | use Meta::Grapher::Moose; | ||
| 16 | use Module::Runtime qw(require_module); | ||
| 17 | |||
| 18 | use Moose; | ||
| 19 | |||
| 20 | has renderer => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'Str', | ||
| 23 | default => 'graphviz', | ||
| 24 | documentation => 'The name of the renderer to use', | ||
| 25 | ); | ||
| 26 | |||
| 27 | with 'MooseX::Getopt::Dashes'; | ||
| 28 | |||
| 29 | sub run { | ||
| 30 | my $class = shift; | ||
| 31 | my $self = $class->new_with_options; | ||
| 32 | |||
| 33 | my $renderer_classname | ||
| 34 | = 'Meta::Grapher::Moose::Renderer::' . ucfirst lc $self->renderer; | ||
| 35 | require_module($renderer_classname); | ||
| 36 | |||
| 37 | # Any command line options that we didn't consume are passed onto the | ||
| 38 | # renderer so it gets a chance to process them. | ||
| 39 | my $renderer = $renderer_classname->new_with_options( | ||
| 40 | argv => $self->extra_argv, | ||
| 41 | ); | ||
| 42 | |||
| 43 | # We pass our main object any command line options that aren't consumed by | ||
| 44 | # the renderer and this class | ||
| 45 | my $grapher = Meta::Grapher::Moose->new_with_options( | ||
| 46 | renderer => $renderer, | ||
| 47 | argv => $renderer->extra_argv, | ||
| 48 | ); | ||
| 49 | |||
| 50 | $grapher->run; | ||
| 51 | |||
| 52 | return; | ||
| 53 | } | ||
| 54 | |||
| 55 | # We can't just override this since the method created for us was installed | ||
| 56 | # directly in this class. Instead wrap it with around and | ||
| 57 | around print_usage_text => sub { | ||
| 58 | ## no critic (InputOutput::RequireCheckedSyscalls) | ||
| 59 | print <<'TEXT'; | ||
| 60 | Many more command line options are available depending on they type of | ||
| 61 | renderer you are using. Please refer to the documentation for the individual | ||
| 62 | renderers or use "perldoc graph-meta.pl" for an overview. | ||
| 63 | TEXT | ||
| 64 | }; | ||
| 65 | |||
| 66 | __PACKAGE__->meta->make_immutable; | ||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | # ABSTRACT: Module supporting command line interface for Meta::Grapher::Moose | ||
| 71 | |||
| 72 | __END__ |