| 1 | package Meta::Grapher::Moose::Role::HasOutput; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use namespace::autoclean; | ||
| 6 | |||
| 7 | our $VERSION = '1.03'; | ||
| 8 | |||
| 9 | use Moose::Role; | ||
| 10 | |||
| 11 | has output => ( | ||
| 12 | is => 'ro', | ||
| 13 | isa => 'Str', | ||
| 14 | ); | ||
| 15 | |||
| 16 | has format => ( | ||
| 17 | is => 'ro', | ||
| 18 | isa => 'Str', | ||
| 19 | lazy => 1, | ||
| 20 | builder => '_build_format', | ||
| 21 | ); | ||
| 22 | |||
| 23 | sub has_output { defined $_[0]->output } | ||
| 24 | |||
| 25 | sub _build_format { | ||
| 26 | my $self = shift; | ||
| 27 | |||
| 28 | # attempt to use the file extension as the format, if there is a usable | ||
| 29 | # extension that is... | ||
| 30 | my $ext; | ||
| 31 | unless ( $self->has_output | ||
| 32 | && ( ($ext) = $self->output =~ /[.]([^.]+)\z/ ) ) { | ||
| 33 | return 'src'; | ||
| 34 | } | ||
| 35 | |||
| 36 | return $ext; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | # ABSTRACT: Role with standard way to specify Meta::Grapher::Moose output | ||
| 42 | |||
| 43 | __END__ |