| 1 | package WWW::MenuGrinder::Plugin::DefaultTarget; | ||
| 2 | our $VERSION = '0.01_01'; | ||
| 3 | |||
| 4 | |||
| 5 | # ABSTRACT: WWW::MenuGrinder plugin that sets a default link target. | ||
| 6 | |||
| 7 | use Moose; | ||
| 8 | |||
| 9 | with 'WWW::MenuGrinder::Role::ItemPreMogrifier'; | ||
| 10 | |||
| 11 | sub plugin_depends { qw(Visitor) } | ||
| 12 | |||
| 13 | sub item_pre_mogrify { | ||
| 14 | my ($self, $item) = @_; | ||
| 15 | |||
| 16 | if (exists $item->{location} && !exists $item->{target}) { | ||
| 17 | if (ref $item->{location} eq "ARRAY") { | ||
| 18 | $item->{target} = "/" . $item->{location}[0]; | ||
| 19 | } elsif (ref $item->{location} eq "HASH") { | ||
| 20 | $item->{target} = "/"; # XML::Simple is stupid. | ||
| 21 | } else { | ||
| 22 | $item->{target} = "/" . $item->{location}; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | return $item; | ||
| 27 | } | ||
| 28 | |||
| 29 | no Moose; | ||
| 30 | 1; | ||
| 31 | |||
| 32 | |||
| 33 | __END__ | ||
| 34 | =head1 NAME | ||
| 35 | |||
| 36 | WWW::MenuGrinder::Plugin::DefaultTarget - WWW::MenuGrinder plugin that sets a default link target. | ||
| 37 | |||
| 38 | =head1 VERSION | ||
| 39 | |||
| 40 | version 0.01_01 | ||
| 41 | |||
| 42 | =head1 DESCRIPTION | ||
| 43 | |||
| 44 | C<WWW::MenuGrinder::Plugin::DefaultTarget> is a plugin for C<WWW::MenuGrinder>. | ||
| 45 | You should not use it directly, but include it in the C<plugins> section of a | ||
| 46 | C<WWW::MenuGrinder> config. | ||
| 47 | |||
| 48 | When loaded, this plugin will create a C<target> (link target) key for each item | ||
| 49 | of the menu that doesn't have one, but which does have a C<location> key. If an | ||
| 50 | item has multiple C<locations>, the first is used to set the C<target>. | ||
| 51 | |||
| 52 | =head2 Configuration | ||
| 53 | |||
| 54 | None. | ||
| 55 | |||
| 56 | =head2 Required Methods | ||
| 57 | |||
| 58 | None. | ||
| 59 | |||
| 60 | =head2 Dependencies | ||
| 61 | |||
| 62 | C<WWW::MenuGrinder::Plugin::Visitor>. | ||
| 63 | |||
| 64 | =head1 AUTHOR | ||
| 65 | |||
| 66 | Andrew Rodland <andrew@hbslabs.com> | ||
| 67 | |||
| 68 | =head1 COPYRIGHT AND LICENSE | ||
| 69 | |||
| 70 | This software is copyright (c) 2009 by HBS Labs, LLC.. | ||
| 71 | |||
| 72 | This is free software; you can redistribute it and/or modify it under | ||
| 73 | the same terms as perl itself. | ||
| 74 |