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

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

use tranfer error messages in progress list. various bug fixes.

  • Property svn:eol-style set to LF
File size: 3.1 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    localized_msg
34/);
35
36# $param is a hash with :
37# key : member name
38sub new {
39    my ( $class, $params ) = @_;
40   
41    $params ||= {};
42   
43    my $self = bless $params, $class ;
44
45    # member accessors initialization
46    eval {
47        map {
48            $self->$_(
49                $params->{$_}
50            );
51        }
52        keys %$params;
53    };
54    if($@){
55        warn $@;       
56    }
57
58    # must be defined in child class
59    $self->Init();
60
61    return $self;
62}
63
64
65sub read_params {
66    my( $self, $file, $key ) = @_ ;
67
68    my $expr_params ;
69    eval { $expr_params = read_file( $file ); } ;
70
71    my $paramValues = [] ;
72    if($expr_params){
73        my $expr = '$paramValues = ' ;
74        $expr .=  "$expr_params  " ;
75        eval $expr ;
76    }
77    return unless 'ARRAY' eq ref $paramValues ;
78        if($@){
79            die "Cannot load data $@"; 
80        }
81    if(scalar(@$paramValues )){
82        my $params = $paramValues->[0] ;
83        $self->set_key_values($params, $key);
84    }
85}
86
87
88sub set_key_values {
89    my ( $self, $params, $key )= @_;
90    if (defined $key) { 
91        foreach( keys %$params ) {
92            $self->{$key}->{$_} = $params->{$_} ;
93        }
94    }
95    else {
96        foreach( keys %$params ) {
97            $self->{$_} = $params->{$_} ;
98        }
99    }
100}
101
102
103sub get_storable {
104    my ( $self, $keys ) = @_;   
105
106    my $data = {
107        map {
108            $_ => $self->{$_},
109          }
110          @$keys
111    };
112   
113    $data;
114}
115
116
1171;
Note: See TracBrowser for help on using the repository browser.