summaryrefslogtreecommitdiff
path: root/LedgerSMB/Menu.pm
blob: 5c017a7cd4f2396ad04c423c1e91b34d9581c915 (plain)
  1. =head1 NAME
  2. LedgerSMB::Menu: Menu Handling Back-end Routines for LedgerSMB
  3. =head1 SYNOPSIS
  4. Provides the functions for generating the data structures for the LedgerSMB
  5. menu.
  6. =head1 COPYRIGHT
  7. Copyright (c) 2007 The LedgerSMB Core Team. Licensed under the GNU General
  8. Public License version 2 or at your option any later version. Please see the
  9. included COPYRIGHT and LICENSE files for more information.
  10. =cut
  11. package LedgerSMB::Menu;
  12. use Config::Std;
  13. use base(qw(LedgerSMB));
  14. 1;
  15. =head1 METHODS
  16. =over
  17. =item new({files => ['path/to/file/glob' ... ], user = $user_ref})
  18. Creates a new Menu data structure with the files listed and the files in the
  19. paths.
  20. =cut
  21. sub new {
  22. my ($class, $args) = @_;
  23. my $self = {};
  24. bless ($self, $class);
  25. my $index = 1;
  26. for $file_glob (@{$args->{files}}){
  27. for $file (glob($file_glob)){
  28. my %config;
  29. read_config($file => %config );
  30. for $key (keys %config){
  31. next if $args->{user}->{acs} =~ /$key/;
  32. my $orig_key = $key;
  33. my $ref = $self;
  34. while ($key =~ s/^([^-]*)--//){
  35. $ref->{subs} ||= {};
  36. $ref->{subs}->{$1} ||= {};
  37. $ref = $ref->{subs}->{$1};
  38. }
  39. $ref->{subs} ||= {};
  40. $ref->{subs}->{key} ||= {};
  41. $ref = $ref->{subs}->{$key};
  42. for (keys %{$config{$orig_key}}){
  43. $ref->{$_} = ${$config{$orig_key}}{$_};
  44. }
  45. $ref->{id} = $index;
  46. $ref->{label} = $key;
  47. ++$index;
  48. }
  49. }
  50. }
  51. return $self;
  52. }
  53. 1;
  54. =back