- Location:
- /LATMOS-Accounts
- Files:
-
- 11 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
/LATMOS-Accounts/lib/LATMOS/Accounts.pm
r20 r30 4 4 use strict; 5 5 use warnings; 6 use base qw(Config::IniFiles); 7 use LATMOS::Accounts::Bases; 6 8 7 require Exporter;9 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 8 10 9 our @ISA = qw(Exporter); 11 sub new { 12 my ($class, $config) = @_; 10 13 11 # Items to export into callers namespace by default. Note: do not export 12 # names by default without a very good reason. Use EXPORT_OK instead. 13 # Do not simply export all your public functions/methods/constants. 14 $config ||= '/etc/latmos-account.ini'; 14 15 15 # This allows declaration use LATMOS::Accounts ':all'; 16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK 17 # will save memory. 18 our %EXPORT_TAGS = ( 'all' => [ qw( 19 20 ) ] ); 16 my $self = Config::IniFiles->new( 17 -file => $config 18 ); 21 19 22 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); 20 bless($self, $class) 21 } 23 22 24 our @EXPORT = qw( 25 26 ); 23 sub base { 24 my ($self, $section) = @_; 25 # this method perform a cache 26 $self->{_bases}{$section} and return $self->{_bases}{$section}; 27 $self->load_base($section) ? $self->{_bases}{$section} : undef; 28 } 27 29 28 our $VERSION = '0.01'; 30 sub default_base { 31 my ($self) = @_; 32 my $default = $self->dafault_base_name or return; 33 $self->base($default); 34 } 29 35 36 # load or a if need base 37 sub load_base { 38 my ($self, $section) = @_; 39 return ($self->{_bases}{$section} ||= $self->_load_base($section)) 40 ? 1 41 : 0; 42 } 30 43 31 # Preloaded methods go here. 44 # do the bad work 45 sub _load_base { 46 my ($self, $section) = @_; 47 my $type = $self->val($section, 'type') or return; 48 my %params = map { $_ => ($self->val($section, $_) || undef) } $self->Parameters($section); 49 return LATMOS::Accounts::Bases->new($type, %params); 50 } 51 52 sub default_base_name { 53 my ($self) = @_; 54 $self->val('_default_', 'base', ($self->list_bases)[0]); 55 } 56 57 sub list_bases { 58 my ($self) = @_; 59 grep { 60 !m/^_.*_$/ 61 } $self->Sections 62 } 63 64 sub load_all_base { 65 my ($self) = @_; 66 foreach ($self->list_bases) { 67 $self->load_base($_) or do { 68 warn "Cannot load base $_\n"; 69 return 0; 70 }; 71 } 72 1; 73 } 32 74 33 75 1; 76 34 77 __END__ 35 78 # Below is stub documentation for your module. You'd better edit it! -
/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r20 r30 78 78 } 79 79 80 =head2 list_objects($otype) 81 82 Return the list of UID for object of $otype. 83 84 =cut 85 86 sub list_objects { 87 my ($self, $otype) = @_; 88 my $pclass = $self->_load_obj_class($otype) or return; 89 $pclass->list($self); 90 } 91 80 92 =head2 get_object($type, $id) 81 93 … … 88 100 my ($self, $otype, $id) = @_; 89 101 90 return LATMOS::Accounts::Bases::Objects-> new($self, $otype, $id);102 return LATMOS::Accounts::Bases::Objects->_new($self, $otype, $id); 91 103 } 92 104 … … 102 114 sub create_object { 103 115 my ($self, $otype, $id, %data) = @_; 104 return; 116 my $pclass = $self->_load_obj_class($otype); 117 $pclass->create($id, %data) or return; 118 $self->get_object($otype, $id); 105 119 } 106 120 -
/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r20 r30 22 22 =cut 23 23 24 =head2 new($base, $type, $id, ...)24 =head2 list($base) 25 25 26 Return a new object of type $type having unique identifier 27 $id, all remaining arguments are passed to the subclass. 26 List object supported by this module existing in base $base 27 28 =cut 29 30 sub list { 31 my ($class) = @_; 32 return; 33 } 34 35 =head2 new($base, $id) 36 37 Create a new object having $id as uid. 28 38 29 39 =cut 30 40 31 41 sub new { 42 my ($class, $base, $id, @args) = @_; 43 # So can be call as $class->SUPER::new() 44 bless { 45 _base => $base, 46 _type => ($class =~ m/[^:]*$/)[0], 47 }, $class; 48 } 49 50 # _new($base, $type, $id, ...) 51 52 # Return a new object of type $type having unique identifier 53 # $id, all remaining arguments are passed to the subclass. 54 55 sub _new { 32 56 my ($class, $base, $otype, $id, @args) = @_; 33 57 … … 39 63 return $newobj; 40 64 } 65 66 =head2 type 67 68 Return the type of the object 69 70 =cut 41 71 42 72 sub type { -
/LATMOS-Accounts/t/11_bases_unix.t
r20 r30 56 56 is($user->get_field('shell'), '/bin/tcsh', 'Can get modified login shell'); 57 57 58 warn $dir 59 #system('rm', '-fr', $dir); 58 system('rm', '-fr', $dir);
Note: See TracChangeset
for help on using the changeset viewer.