| 1 | package WWW::MenuGrinder::Plugin::DefaultTarget; | ||
| 2 | BEGIN { | ||
| 3 | $WWW::MenuGrinder::Plugin::DefaultTarget::VERSION = '0.06'; | ||
| 4 | } | ||
| 5 | |||
| 6 | # ABSTRACT: WWW::MenuGrinder plugin that sets a default link target. | ||
| 7 | |||
| 8 | use Moose; | ||
| 9 | |||
| 10 | with 'WWW::MenuGrinder::Role::ItemMogrifier'; | ||
| 11 | |||
| 12 | sub item_mogrify { | ||
| 13 | my ($self, $item) = @_; | ||
| 14 | |||
| 15 | if (exists $item->{location} && !exists $item->{target}) { | ||
| 16 | if (ref $item->{location} eq "ARRAY") { | ||
| 17 | $item->{target} = "/" . $item->{location}[0]; | ||
| 18 | } elsif (ref $item->{location} eq "HASH") { | ||
| 19 | $item->{target} = "/"; # XML::Simple is stupid. | ||
| 20 | } else { | ||
| 21 | $item->{target} = "/" . $item->{location}; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | return $item; | ||
| 26 | } | ||
| 27 | |||
| 28 | __PACKAGE__->meta->make_immutable; | ||
| 29 | |||
| 30 | no Moose; | ||
| 31 | 1; | ||
| 32 | |||
| 33 | |||
| 34 | __END__ |