Changes in / [20:30]


Ignore:
Location:
/LATMOS-Accounts
Files:
11 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • /LATMOS-Accounts/lib/LATMOS/Accounts.pm

    r20 r30  
    44use strict; 
    55use warnings; 
     6use base qw(Config::IniFiles); 
     7use LATMOS::Accounts::Bases; 
    68 
    7 require Exporter; 
     9our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 
    810 
    9 our @ISA = qw(Exporter); 
     11sub new { 
     12    my ($class, $config) = @_; 
    1013 
    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'; 
    1415 
    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    ); 
    2119 
    22 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); 
     20    bless($self, $class) 
     21} 
    2322 
    24 our @EXPORT = qw( 
    25          
    26 ); 
     23sub 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} 
    2729 
    28 our $VERSION = '0.01'; 
     30sub default_base { 
     31    my ($self) = @_; 
     32    my $default = $self->dafault_base_name or return; 
     33    $self->base($default); 
     34} 
    2935 
     36# load or a if need base 
     37sub load_base { 
     38    my ($self, $section) = @_; 
     39    return ($self->{_bases}{$section} ||= $self->_load_base($section)) 
     40        ? 1 
     41        : 0; 
     42} 
    3043 
    31 # Preloaded methods go here. 
     44# do the bad work 
     45sub _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 
     52sub default_base_name { 
     53    my ($self) = @_; 
     54    $self->val('_default_', 'base', ($self->list_bases)[0]); 
     55} 
     56 
     57sub list_bases { 
     58    my ($self) = @_; 
     59    grep { 
     60        !m/^_.*_$/ 
     61    } $self->Sections 
     62} 
     63 
     64sub 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} 
    3274 
    33751; 
     76 
    3477__END__ 
    3578# Below is stub documentation for your module. You'd better edit it! 
  • /LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r20 r30  
    7878} 
    7979 
     80=head2 list_objects($otype) 
     81 
     82Return the list of UID for object of $otype. 
     83 
     84=cut 
     85 
     86sub list_objects { 
     87    my ($self, $otype) = @_; 
     88    my $pclass = $self->_load_obj_class($otype) or return; 
     89    $pclass->list($self); 
     90} 
     91 
    8092=head2 get_object($type, $id) 
    8193 
     
    88100    my ($self, $otype, $id) = @_; 
    89101 
    90     return LATMOS::Accounts::Bases::Objects->new($self, $otype, $id); 
     102    return LATMOS::Accounts::Bases::Objects->_new($self, $otype, $id); 
    91103} 
    92104 
     
    102114sub create_object { 
    103115    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); 
    105119} 
    106120 
  • /LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r20 r30  
    2222=cut 
    2323 
    24 =head2 new($base, $type, $id, ...) 
     24=head2 list($base) 
    2525 
    26 Return a new object of type $type having unique identifier 
    27 $id, all remaining arguments are passed to the subclass. 
     26List object supported by this module existing in base $base 
     27 
     28=cut 
     29 
     30sub list { 
     31    my ($class) = @_; 
     32    return; 
     33} 
     34 
     35=head2 new($base, $id) 
     36 
     37Create a new object having $id as uid. 
    2838 
    2939=cut 
    3040 
    3141sub 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 
     55sub _new { 
    3256    my ($class, $base, $otype, $id, @args) = @_; 
    3357 
     
    3963    return $newobj; 
    4064} 
     65 
     66=head2 type 
     67 
     68Return the type of the object 
     69 
     70=cut 
    4171 
    4272sub type { 
  • /LATMOS-Accounts/t/11_bases_unix.t

    r20 r30  
    5656is($user->get_field('shell'), '/bin/tcsh', 'Can get modified login shell'); 
    5757 
    58 warn $dir 
    59 #system('rm', '-fr', $dir); 
     58system('rm', '-fr', $dir); 
Note: See TracChangeset for help on using the changeset viewer.