WE/Util/HWRights.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 55 CC 5 SCAR 29.7
CC
5
Cov
0%
parse
30.0
new
2.0
BEGIN
2.0
CRAP 19.5
1 # -*- perl -*-
2  
3 #
4 # $Id: HWRights.pm,v 1.4 2004/02/03 15:07:42 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2001 Online Office Berlin. All rights reserved.
8 # Copyright (C) 2002 Slaven Rezic.
9 # This is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License, see the file COPYING.
11  
12 #
13 # Mail: slaven@rezic.de
14 # WWW: http://we-framework.sourceforge.net
15 #
16  
17 package WE::Util::HWRights;
18  
19 use strict;
20 use vars qw($VERSION);
21 $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
22  
23 die "This is work in progres... use WE::Util::SimpleRights instead...!";
24  
25 sub new {
26 my($class, $rightstring) = @_;
27 bless \$rightstring, $class;
28 }
29  
30 # XXX check the HW semantics if there are missing right bits
31 sub parse {
32 my($class, $rightstring) = @_;
33  
34 if (!defined $rightstring || $rightstring =~ /^\s*$/) {
35 return {'R' => ['a','o'], 'U' => ['a'], 'W' => ['a']};
36 }
37  
38 my $rights = {'R' => 'o', 'U' => ['a'], 'W' => ['a']};
39 foreach (split /\s*;\s*/, $rightstring) {
40 if (!/^([RWU]):(.*)$/) {
41 die "Invalid right string component $_";
42 }
43 my($action, $entities) = ($1, $2);
44 foreach (split /\s*,\s*/, $entities) {
45 if (!/^(?:(a)|([ug])\s+(.*))$/) {
46 die "Invalid right string component $_";
47 }
48 if ($1 eq 'a') {
49 push @{$rights->{$action}}, 'a';
50 } else {
51 my($entity_group, $entities) = ($1, $2);
52 foreach (split /\s+/, $entities) {
53 push @{$rights->{$action}}, "$entity_group $_";
54 }
55 }
56 }
57 }
58 }
59  
60 1;
61  
62 __END__