kleine Weiterentwicklung
[kivitendo-erp.git] / SL / MenuItem.pm
1 package SL::MenuItem;
2
3 use strict;
4
5 sub new {
6   my ($class, %params) = @_;
7
8   my $obj = bless {}, $class;
9   $obj->{fullname} = $params{name};
10   my $values       = $params{item};
11
12   $obj->{ACCESS} = delete $values->{ACCESS};
13   $obj->{module} = delete $values->{module} || die 'menuitem - need module';
14   $obj->{action} = delete $values->{action} || die 'menuitem - need action';
15
16   $obj->{params} = $values;
17 }
18
19 sub ACCESS { $_[0]{ACCESS} }
20 sub action { $_[0]{action} }
21 sub module { $_[0]{module} }
22 sub params { $_[0]{params} }
23
24 sub name { $_[0]{name} ||= $_[0]->_init_name }
25 sub _init_name { my $name = $_[0]{fullname}; $name =~ s/.*--//; $name }
26 sub path { @{ $_[0]{path} ||= [ $_[0]->_init_path ] } }
27 sub _init_path { my $name = $_[0]{fullname}; split /--/, $name }
28
29 sub children { }
30 sub siblings {}
31 sub parent {}
32
33
34 ###### internal stuff #######
35
36
37
38 1;
39
40 __END__
41
42 =encoding utf-8
43
44 =head1 NAME
45
46 SL::MenuItem - wrapper class for menu items
47
48 =head1 SYNOPSIS
49
50   use SL::Menu;
51
52   for my item (Menu->new->menuitems) {
53     next unless $item->access;
54
55     make_your_own_menuentry_from(
56       module => $item->module,
57       action => $iten->action,
58       params => $item->params,
59       name   => $item->name,
60       path   => $item->path,
61       children => $item->children,
62       parent => $item->parent,
63     );
64   }
65
66 =head1 DESCRIPTION
67
68 This provides some wrapper methods around the raw entries in menu.ini. It sorts through expected information like module and action, wraps access calls for you and gives you tree access to siblings, children and parent elements in the menu structure.
69
70 =head1 METHODS
71
72 =over 4
73
74 =item new
75
76 =item access
77
78 =item module
79
80 =item params
81
82 =item name
83
84 =item path
85
86 =item children
87
88 =item parent
89
90 =item siblings
91
92 =back
93
94 =head1 BUGS
95
96 =head1 AUTHOR
97
98 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
99
100 =cut