source: extensions/pLoader/trunk/src/Uploader/Object.pm @ 6426

Last change on this file since 6426 was 6426, checked in by ronosman, 14 years ago

Bug 1710 fixed : pLoader lack of concurrency support causes data inconsistency.

  • Property svn:eol-style set to LF
File size: 3.0 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
5# +-----------------------------------------------------------------------+
6# | This program is free software; you can redistribute it and/or modify  |
7# | it under the terms of the GNU General Public License as published by  |
8# | the Free Software Foundation                                          |
9# |                                                                       |
10# | This program is distributed in the hope that it will be useful, but   |
11# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13# | General Public License for more details.                              |
14# |                                                                       |
15# | You should have received a copy of the GNU General Public License     |
16# | along with this program; if not, write to the Free Software           |
17# | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18# | USA.                                                                  |
19# +-----------------------------------------------------------------------+
20package Uploader::Object;
21use strict;
22use Data::Dumper;
23use Storable;
24use File::Slurp ; 
25use Data::Dumper;
26use base qw/
27               Class::Accessor::Fast
28           /;
29
30__PACKAGE__->mk_accessors(qw/
31    version
32    storable_file
33/);
34
35# $param is a hash with :
36# key : member name
37sub new {
38    my ( $class, $params ) = @_;
39   
40    $params ||= {};
41   
42    my $self = bless $params, $class ;
43
44    # member accessors initialization
45    eval {
46        map {
47            $self->$_(
48                $params->{$_}
49            );
50        }
51        keys %$params;
52    };
53    if($@){
54        warn $@;       
55    }
56
57    # must be defined in child class
58    $self->Init();
59
60    return $self;
61}
62
63
64sub read_params {
65    my( $self, $file, $key ) = @_ ;
66
67    my $expr_params ;
68    eval { $expr_params = read_file( $file ); } ;
69
70    my $paramValues = [] ;
71    if($expr_params){
72        my $expr = '$paramValues = ' ;
73        $expr .=  "$expr_params  " ;
74        eval $expr ;
75    }
76    return unless 'ARRAY' eq ref $paramValues ;
77        if($@){
78            die "Cannot load data $@"; 
79        }
80    if(scalar(@$paramValues )){
81        my $params = $paramValues->[0] ;
82        $self->set_key_values($params, $key);
83    }
84}
85
86
87sub set_key_values {
88    my ( $self, $params, $key )= @_;
89    if (defined $key) { 
90        foreach( keys %$params ) {
91            $self->{$key}->{$_} = $params->{$_} ;
92        }
93    }
94    else {
95        foreach( keys %$params ) {
96            $self->{$_} = $params->{$_} ;
97        }
98    }
99}
100
101
102sub get_storable {
103    my ( $self, $keys ) = @_;   
104
105    my $data = {
106        map {
107            $_ => $self->{$_},
108          }
109          @$keys
110    };
111   
112    $data;
113}
114
115
1161;
Note: See TracBrowser for help on using the repository browser.