Markup/YAML.pm untested

filter: Statementstmt 0.0% 0 / 16 Branchbran 0.0% 0 / 4 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 24 CC 3 SCAR 20.8
CC
3
Cov
0%
get_data
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 8.0
1 #
2 # YUI::MenuBar::Markup::YAML
3 #
4 # Author(s): Pablo Fischer (pfischer@cpan.org)
5 # Created: 01/19/2010 10:32:05 PST 10:32:05
6 package YUI::MenuBar::Markup::YAML;
7  
8 =head1 NAME
9  
10 YUI::MenuBar::Markup::YAML - Provides the menu content from a YAML file
11  
12 =head1 DESCRIPTION
13  
14 It reads a L<YAML> file, gets the content and returns it so that
15 L<YUI::MenuBar::Markup> can use it for building YUI menu.
16  
17 It uses L<YAML::Syck> for reading the YAML file.
18  
19 An example of a YAML file can be:
20  
21 menu:
22 -
23 name: Searchers
24 menu:
25 -
26 name: Yahoo!
27 link: http://search.yahoo.com
28 -
29 name: Google
30 link: http://www.google.com
31 -
32 name: Altavista
33 link: http://www.altavista.com
34 -
35 name: Mail
36 menu:
37 -
38 name: Yahoo Mail!
39 link: http://mail.yahoo.com
40 -
41 name: Gmail
42 link: http://gmail.com
43 -
44  
45 And so on, for any additional sub-menu you should just declare a new I<menu:>
46 and then list the items of it.
47  
48 Valid items or any menu item are:
49  
50 =over 4
51  
52 =item * name: The name (text) of the item.
53  
54 =item * link: The link where the item will be pointing
55  
56 =item * menu: In case the item will have sub-items
57  
58 =back
59  
60 =cut
61 use Mouse;
62 use YAML::Syck;
63  
64 our $VERSION = '0.01';
65  
66 =head1 Attributes
67  
68 =over 4
69  
70 =item B<filename>
71  
72 YAML path filename
73  
74 =back
75  
76 =cut
77 has 'filename' => (
78 is => 'rw',
79 isa => 'Str',
80 required => 1);
81  
82 =head1 Methods
83  
84 =head2 B<get_data()>
85  
86 Opens the YAML file (see L<filename>) and looks for the first I<menu> item,
87 once its found then all of its items are returned.
88  
89 The method is called by L<YUI::MenuBar::Markup>.
90  
91 =cut
92 sub get_data {
93 my ($self) = @_;
94  
95 if (!-f $self->{'filename'}) {
96 confess "$self->{'filename'} does not exists";
97 }
98  
99 my $data = LoadFile($self->{'filename'});
100 if (defined $data->{'menu'}) {
101 return $data->{'menu'};
102 }
103  
104 warn "No *menu* item found in $self->{'filename'}, returning undef";
105 return undef;
106 }
107  
108 =head1 AUTHOR
109
110 Pablo Fischer (pablo@pablo.com.mx).
111  
112 =head1 COPYRIGHT
113
114 Copyright (C) 2010 by Pablo Fischer.
115
116 This library is free software; you can redistribute it and/or modify it under
117 the same terms as Perl itself.
118  
119 =cut
120  
121 1;
122