Changeset 1047 for trunk


Ignore:
Timestamp:
06/01/12 08:25:18 (12 years ago)
Author:
nanardon
Message:
  • order documentation
File:
1 edited

Legend:

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

    r1044 r1047  
    105105        !m/^sync:/ 
    106106    } $self->Sections 
     107} 
     108 
     109=head2 default_base_name 
     110 
     111Return the default base name according config file 
     112 
     113=cut 
     114 
     115sub default_base_name { 
     116    my ($self) = @_; 
     117    $self->val('_default_', 'base', ($self->list_bases)[0]); 
     118} 
     119 
     120=head2 base($basename) 
     121 
     122Return a L<LATMOS::Accounts::Base> object over base named $basename 
     123defined in the config file. 
     124 
     125The base is loaded by this function. 
     126 
     127=cut 
     128 
     129sub base { 
     130    my ($self, $section) = @_; 
     131    # this method perform a cache 
     132    $self->_load_base($section || $self->default_base_name); 
     133} 
     134 
     135# do the bad work 
     136sub _load_base { 
     137    my ($self, $section) = @_; 
     138    my $type = $self->val($section, 'type') or return; 
     139    my %params = ( 
     140        map { $_ => ($self->val($section, $_)) } $self->Parameters($section), 
     141        defattr => { map { $_ => ($self->val('_defattr_', $_)) } $self->Parameters('_defattr_') }, 
     142    ); 
     143    my $base = LATMOS::Accounts::Bases->new( 
     144        $type, 
     145        %params, 
     146        label => $section, 
     147        acls => $self->{_acls}, 
     148        allowed_values => $self->{_allowed_values}, 
     149        configdir => $self->_configdir, 
     150        _la => $self, 
     151    ) or do { 
     152        la_log(LA_WARN, "Cannot instanciate base $section ($type)"); 
     153        return; 
     154    }; 
     155    $base->load or return; 
     156    $base; 
     157} 
     158 
     159=head2 list_synchro 
     160 
     161List synchronisation setup in L<latmos-accounts.ini> 
     162 
     163=cut 
     164 
     165sub list_synchro { 
     166    my ($self) = @_; 
     167    grep { $_ } map { /^sync:(.*)$/; $1 } $self->Sections 
     168} 
     169 
     170=head2 default_synchro_name 
     171 
     172Return de default synchronisation name 
     173 
     174=cut 
     175 
     176sub default_synchro_name { 
     177    my ($self) = @_; 
     178    $self->val('_default_', 'sync'); 
     179} 
     180 
     181=head2 default_synchro 
     182 
     183Return a reference to default synchronisation object 
     184 
     185=cut 
     186 
     187sub default_synchro { 
     188    my ($self, %options) = @_; 
     189    my $syncname = $self->default_synchro_name or do { 
     190        la_log(LA_ERR, 'Cannot find default synchro in config'); 
     191        return; 
     192    }; 
     193    $self->create_synchro($syncname, %options); 
     194} 
     195 
     196=head2 create_synchro($name, %options) 
     197 
     198Return a reference to synchronisation object for C<$name> synchronisation. 
     199 
     200=cut 
     201 
     202sub create_synchro { 
     203    my ($self, $name, %options) = @_; 
     204 
     205    # taking options from config 
     206    if ($name) { 
     207        foreach my $param ($self->Parameters("sync:$name")) { 
     208            if (!defined($options{$param})) { 
     209                my @args = $self->val("sync:$name", $param); 
     210                $options{$param} = ($args[1] || $param eq 'to') 
     211                    ? [ @args ] 
     212                    : $args[0]; 
     213            } 
     214        } 
     215    } 
     216 
     217    my $labfrom = $options{from} ? $self->base($options{from}) : $self->default_base; 
     218 
     219    my @labto = 
     220        grep { $_ } 
     221        map { $self->base($_) } 
     222        @{ $options{to} || []} 
     223        or do { 
     224        la_log(LA_ERR, "No destination base load in this synchro"); 
     225        return; 
     226    }; 
     227 
     228    my $sync = LATMOS::Accounts::Synchro->new( 
     229        $labfrom, [ @labto ], 
     230        state_dir => ($self->val('_default_', 'state_dir') || undef), 
     231        %options, 
     232        name => $name, 
     233    ); 
     234} 
     235 
     236=head2 sync_access($name, %options) 
     237 
     238Return a L<LATMOS::Accounts::SynchAccess> object over C<$name> synchronisation. 
     239 
     240=cut 
     241 
     242sub sync_access { 
     243    my ($self, $name, %options) = @_; 
     244 
     245    my @obases; 
     246    if ($name) { 
     247        @obases = 
     248        (map { $self->base($_) } ($self->sync_from_name($name), $self->val("sync:$name", 'to'))); 
     249    } elsif(@{ $options{bases} || []}) { 
     250        @obases = map { $self->base($_) } @{ $options{bases} || []}; 
     251    } elsif (my $sname = $self->default_synchro_name) { 
     252        @obases = (map { $self->base($_) } 
     253            ($self->sync_from_name($sname), $self->val("sync:$sname", 'to')) 
     254        ); 
     255    } 
     256 
     257    LATMOS::Accounts::SynchAccess->new([ @obases ]); 
    107258} 
    108259 
     
    137288} 
    138289 
    139 =head2 default_base_name 
    140  
    141 Return the default base name according config file 
    142  
    143 =cut 
    144  
    145 sub default_base_name { 
    146     my ($self) = @_; 
    147     $self->val('_default_', 'base', ($self->list_bases)[0]); 
    148 } 
    149  
    150 =head2 base($basename) 
    151  
    152 Return a L<LATMOS::Accounts::Base> object over base named $basename 
    153 defined in the config file. 
    154  
    155 The base is loaded by this function. 
    156  
    157 =cut 
    158  
    159 sub base { 
    160     my ($self, $section) = @_; 
    161     # this method perform a cache 
    162     $self->_load_base($section || $self->default_base_name); 
    163 } 
    164  
    165 # do the bad work 
    166 sub _load_base { 
    167     my ($self, $section) = @_; 
    168     my $type = $self->val($section, 'type') or return; 
    169     my %params = ( 
    170         map { $_ => ($self->val($section, $_)) } $self->Parameters($section), 
    171         defattr => { map { $_ => ($self->val('_defattr_', $_)) } $self->Parameters('_defattr_') }, 
    172     ); 
    173     my $base = LATMOS::Accounts::Bases->new( 
    174         $type, 
    175         %params, 
    176         label => $section, 
    177         acls => $self->{_acls}, 
    178         allowed_values => $self->{_allowed_values}, 
    179         configdir => $self->_configdir, 
    180         _la => $self, 
    181     ) or do { 
    182         la_log(LA_WARN, "Cannot instanciate base $section ($type)"); 
    183         return; 
    184     }; 
    185     $base->load or return; 
    186     $base; 
    187 } 
    188  
    189 =head2 list_synchro 
    190  
    191 List synchronisation setup in L<latmos-accounts.ini> 
    192  
    193 =cut 
    194  
    195 sub list_synchro { 
    196     my ($self) = @_; 
    197     grep { $_ } map { /^sync:(.*)$/; $1 } $self->Sections 
    198 } 
    199  
    200 =head2 default_synchro_name 
    201  
    202 Return de default synchronisation name 
    203  
    204 =cut 
    205  
    206 sub default_synchro_name { 
    207     my ($self) = @_; 
    208     $self->val('_default_', 'sync'); 
    209 } 
    210  
    211 =head2 default_synchro 
    212  
    213 Return a reference to default synchronisation object 
    214  
    215 =cut 
    216  
    217 sub default_synchro { 
    218     my ($self, %options) = @_; 
    219     my $syncname = $self->default_synchro_name or do { 
    220         la_log(LA_ERR, 'Cannot find default synchro in config'); 
    221         return; 
    222     }; 
    223     $self->create_synchro($syncname, %options); 
    224 } 
    225  
    226 =head2 create_synchro($name, %options) 
    227  
    228 Return a reference to synchronisation object for C<$name> synchronisation. 
    229  
    230 =cut 
    231  
    232 sub create_synchro { 
    233     my ($self, $name, %options) = @_; 
    234  
    235     # taking options from config 
    236     if ($name) { 
    237         foreach my $param ($self->Parameters("sync:$name")) { 
    238             if (!defined($options{$param})) { 
    239                 my @args = $self->val("sync:$name", $param); 
    240                 $options{$param} = ($args[1] || $param eq 'to') 
    241                     ? [ @args ] 
    242                     : $args[0]; 
    243             } 
    244         } 
    245     } 
    246  
    247     my $labfrom = $options{from} ? $self->base($options{from}) : $self->default_base; 
    248  
    249     my @labto = 
    250         grep { $_ } 
    251         map { $self->base($_) } 
    252         @{ $options{to} || []} 
    253         or do { 
    254         la_log(LA_ERR, "No destination base load in this synchro"); 
    255         return; 
    256     }; 
    257  
    258     my $sync = LATMOS::Accounts::Synchro->new( 
    259         $labfrom, [ @labto ], 
    260         state_dir => ($self->val('_default_', 'state_dir') || undef), 
    261         %options, 
    262         name => $name, 
    263     ); 
    264 } 
    265  
    266 =head2 sync_access($name, %options) 
    267  
    268 Return a L<LATMOS::Accounts::SynchAccess> object over C<$name> synchronisation. 
    269  
    270 =cut 
    271  
    272 sub sync_access { 
    273     my ($self, $name, %options) = @_; 
    274  
    275     my @obases; 
    276     if ($name) { 
    277         @obases = 
    278         (map { $self->base($_) } ($self->sync_from_name($name), $self->val("sync:$name", 'to'))); 
    279     } elsif(@{ $options{bases} || []}) { 
    280         @obases = map { $self->base($_) } @{ $options{bases} || []}; 
    281     } elsif (my $sname = $self->default_synchro_name) { 
    282         @obases = (map { $self->base($_) } 
    283             ($self->sync_from_name($sname), $self->val("sync:$sname", 'to')) 
    284         ); 
    285     } 
    286  
    287     LATMOS::Accounts::SynchAccess->new([ @obases ]); 
    288 } 
    289  
    2902901; 
    291291 
Note: See TracChangeset for help on using the changeset viewer.