Changeset 22 for LATMOS-Accounts


Ignore:
Timestamp:
04/10/09 16:14:23 (15 years ago)
Author:
nanardon
Message:
  • start work on core of the system
Location:
LATMOS-Accounts
Files:
2 added
1 edited

Legend:

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

    r3 r22  
    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    my $self = Config::IniFiles->new( 
     15        -file => $config 
     16    ); 
    1417 
    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 ) ] ); 
     18    bless($self, $class) 
     19} 
    2120 
    22 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); 
     21sub base { 
     22    my ($self, $section) = @_; 
     23    # this method perform a cache 
     24    $self->{_bases}{$section} and return $self->{_bases}{$section}; 
     25    $self->load_base($section) ? $self->{_bases}{$section} : undef; 
     26} 
    2327 
    24 our @EXPORT = qw( 
    25          
    26 ); 
     28# load or reload a base 
     29sub load_base { 
     30    my ($self, $section) = @_; 
     31    return ($self->{_bases}{$section} = $self->_load_base($section)) 
     32        ? 1 
     33        : 0; 
     34} 
    2735 
    28 our $VERSION = '0.01'; 
    29  
    30  
    31 # Preloaded methods go here. 
     36# do the bad work 
     37sub _load_base { 
     38    my ($self, $section) = @_; 
     39    my $type = $self->val($section, 'type') or return; 
     40    my %params = map { $_ => ($self->val($section, $_) || undef) } $self->Parameters($section); 
     41    return LATMOS::Accounts::Bases->new($type, %params); 
     42} 
    3243 
    33441; 
Note: See TracChangeset for help on using the changeset viewer.