Changeset 6 for LATMOS-Accounts


Ignore:
Timestamp:
02/27/09 19:00:29 (15 years ago)
Author:
nanardon
Message:
  • can list canonicals fields, eg fixed name to data over all data bases
Location:
LATMOS-Accounts
Files:
1 added
3 edited

Legend:

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

    r5 r6  
    4040    if ($@) { return } # error message ? 
    4141    return "LATMOS::Accounts::Bases::$pclass"->new(%options); 
     42} 
     43 
     44sub _load_obj_class { 
     45    my ($self, $otype) = @_; 
     46 
     47    # finding perl class: 
     48    my $pclass = ref $self; 
     49    $pclass .= '::' . ucfirst(lc($otype)); 
     50    eval "require $pclass;"; 
     51    if ($@) { return } # error message ? 
     52    return $pclass; 
     53} 
     54 
     55=head2 list_canonicals_fields($otype) 
     56 
     57Return the list of supported fields by the database for object type $otype. 
     58 
     59=cut 
     60 
     61sub list_canonicals_fields { 
     62    my ($self, $otype) = @_; 
     63    my $pclass = $self->_load_obj_class($otype) or return; 
     64    $pclass->canonical_fields; 
    4265} 
    4366 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r3 r6  
    3333 
    3434    # finding perl class: 
    35     my $pclass = ref $base; 
    36     $pclass .= '::' . ucfirst(lc($otype)); 
    37     eval "require $pclass;"; 
    38     if ($@) { return } # error message ? 
     35    my $pclass = $base->_load_obj_class($otype) or return; 
    3936    my $newobj = "$pclass"->new($base, $id, @args); 
    4037    $newobj->{_base} = $base; 
     
    5249} 
    5350 
    54 # Preloaded methods go here. 
     51=head2 canonical_fields 
     52 
     53Must return the list of field supported by the object. 
     54 
     55If exists, _canonicals_fields function is called. 
     56 
     57Notice this query will always come from the upstream data base, 
     58this function is just a ficility to store data in the module, but the 
     59underling database can reply themself. 
     60 
     61See list_canonical_fields(). 
     62 
     63=cut 
     64 
     65sub canonical_fields {  
     66    my ($self) = @_; 
     67    if ($self->can('_canonical_fields')) { 
     68        $self->_canonical_fields; 
     69    } else { return; } 
     70} 
    5571 
    56721; 
    5773 
    5874__END__ 
     75 
     76=head1 CANICALS FIELDS 
     77 
     78=head2 User class 
     79 
     80=head2 Group class 
    5981 
    6082=head1 SEE ALSO 
  • LATMOS-Accounts/t/10_bases.t

    r3 r6  
    11use strict; 
    22use warnings; 
    3 use Test::More tests => 11; 
     3use Test::More tests => 12; 
    44 
    55use_ok('LATMOS::Accounts::Bases'); 
     
    1616isa_ok($user, 'LATMOS::Accounts::Bases::Dummy::User'); 
    1717 
     18ok(eq_set([ $dummyb->list_canonicals_fields('user') ], []), "Can get canonicals fields"); 
    1819ok(!$dummyb->is_transactionnal, 'Dummy driver is not transactionnal'); 
Note: See TracChangeset for help on using the changeset viewer.