« lib/Meta/Grapher/Moose/CommandLine.pm
↑ Summary
lib/Meta/Grapher/Moose/Renderer/Plantuml/Link.pm »
| 1 | package Meta::Grapher::Moose::Renderer::Plantuml::Class; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use namespace::autoclean; | ||
| 6 | |||
| 7 | use Digest::MD5 qw( md5_hex ); | ||
| 8 | |||
| 9 | use Moose; | ||
| 10 | |||
| 11 | our $VERSION = '1.03'; | ||
| 12 | |||
| 13 | has id => ( | ||
| 14 | is => 'ro', | ||
| 15 | isa => 'Str', | ||
| 16 | required => 1, | ||
| 17 | ); | ||
| 18 | |||
| 19 | has label => ( | ||
| 20 | is => 'ro', | ||
| 21 | isa => 'Str', | ||
| 22 | lazy => 1, | ||
| 23 | default => sub { shift->name }, | ||
| 24 | ); | ||
| 25 | |||
| 26 | # TODO: This should probably be an enum type | ||
| 27 | has class_type => ( | ||
| 28 | is => 'ro', | ||
| 29 | isa => 'Str', | ||
| 30 | required => 1, | ||
| 31 | ); | ||
| 32 | |||
| 33 | has class_attributes => ( | ||
| 34 | is => 'ro', | ||
| 35 | isa => 'ArrayRef[Str]', | ||
| 36 | required => 1, | ||
| 37 | ); | ||
| 38 | |||
| 39 | has class_methods => ( | ||
| 40 | is => 'ro', | ||
| 41 | isa => 'ArrayRef[Str]', | ||
| 42 | required => 1, | ||
| 43 | ); | ||
| 44 | |||
| 45 | has formatting => ( | ||
| 46 | is => 'ro', | ||
| 47 | isa => 'HashRef[Str]', | ||
| 48 | required => 1, | ||
| 49 | ); | ||
| 50 | |||
| 51 | sub to_plantuml { | ||
| 52 | my $self = shift; | ||
| 53 | |||
| 54 | my $extra = $self->formatting->{ $self->class_type } // q{}; | ||
| 55 | |||
| 56 | my $attributes = join "\n", map {"$_"} sort @{ $self->class_attributes }; | ||
| 57 | my $methods = join "\n", map {"$_()"} sort @{ $self->class_methods }; | ||
| 58 | |||
| 59 | return <<"END"; | ||
| 60 | class "@{[ $self->label ]}" as @{[ md5_hex($self->id) ]} ${extra}{ | ||
| 61 | $attributes | ||
| 62 | $methods | ||
| 63 | } | ||
| 64 | |||
| 65 | END | ||
| 66 | } | ||
| 67 | |||
| 68 | __PACKAGE__->meta->make_immutable; | ||
| 69 | |||
| 70 | 1; | ||
| 71 | |||
| 72 | # ABSTRACT: Utility class for Meta::Grapher::Moose::Renderer::Plantuml | ||
| 73 | |||
| 74 | __END__ |