Revert "Embed Safe 2.07 into Vend::Safe to avoid various problems with recent version...
[interchange.git] / code / UI_Tag / widget_info.coretag
1 UserTag widget-info     Order   name attribute
2 UserTag widget-info     Version $Revision: 1.1 $
3 UserTag widget-info     Routine <<EOR
4 my %wi_attr = ((map { (lc $_, $_) } qw(
5         Widget
6         Documentation
7         Visibility
8         Description
9         Help
10         Multiple
11         Version
12 )), qw(
13         exists  Widget
14 ));
15
16 sub {
17         my ($name, $attr) = @_;
18
19         if (length $name) {
20                 # Global or Local?
21                 my $repo = $Global::CodeDef->{Widget};
22                 $repo = $Vend::Cfg->{CodeDef}{Widget} if $Vend::Cfg->{CodeDef}{Widget}{Widget}{$name};
23                 return unless $repo->{Widget}{$name};
24
25                 if (length $attr) {
26                         # return just one attribute for the given name.
27                         $attr = $wi_attr{lc $attr} or return;
28                         return $repo->{$attr}{$name};
29                 }
30                 else {
31                         # return a hashref with all the available attributes for a given name.
32                         my %build = reverse %wi_attr;
33                         while (my $key = each %build) {
34                                 if (exists $repo->{$key}{$name}) {
35                                         $build{$key} = $repo->{$key}{$name};
36                                 }
37                                 else {
38                                         delete $build{$key};
39                                 }
40                         }
41                         return \%build;
42                 }
43         }
44         else {
45                 # return a hashref of hashrefs for all the widgets and their attributes.
46                 my %build = %{$Global::CodeDef->{Widget}{Widget}};
47                 @build{keys %build} = ($Global::CodeDef->{Widget}) x scalar keys %build;
48                 @build{keys %{$Vend::Cfg->{CodeDef}{Widget}{Widget}}} = ($Vend::Cfg->{CodeDef}{Widget}) x scalar keys %{$Vend::Cfg->{CodeDef}{Widget}{Widget}};
49
50                 foreach my $name (keys %build) {
51                         my $repo = $build{$name};
52                         $build{$name} = {reverse %wi_attr};
53                         while (my $key = each %{$build{$name}}) {
54                                 if (exists $repo->{$key}{$name}) {
55                                         $build{$name}{$key} = $repo->{$key}{$name};
56                                 }
57                                 else {
58                                         delete $build{$name}{$key};
59                                 }
60                         }
61                 }
62                 return \%build;
63         }
64 }
65 EOR