/usr/share/perl5/TWatch/Complete.pm is in libtwatch-perl 0.0.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | package TWatch::Complete;
=head1 NAME
TWatch::Watch::CompleteList - Load and save completed tasks for watch
=cut
use strict;
use warnings;
use utf8;
use XML::Simple;
use TWatch::Config;
use TWatch::Watch::ResultList;
=head1 CONSTRUCTORS
=cut
=head2 new
Load completed tasks and return this object
=cut
sub new
{
my ($class, %opts) = @_;
my $self = bless \%opts ,$class;
$self->load if $self->{cfile};
return $self;
}
=head1 METHODS
=cut
=head2 load
Load completed tasks
=cut
sub load
{
my ($self) = @_;
my $xs = XML::Simple->new(
NoAttr => 1,
ForceArray => ['watch', 'result'],
GroupTags => {
'watches' => 'watch',
'complete' => 'result',
}
);
# Load completed tasks for project
my $complete = $xs->XMLin( $self->{cfile} );
# Fix XML in
for my $name ( keys %{ $complete->{watches} } )
{
# Add empty array even watch empty
$complete->{watches}{$name}{complete} = []
unless %{ $complete->{watches}{$name} };
# Convert empty hashes in empty strings
for my $result ( @{ $complete->{watches}{$name}{complete} } )
{
for my $key ( keys %$result)
{
$result->{$key} = ''
if 'HASH' eq ref $result->{$key} and !%{$result->{$key}};
}
}
my $results = TWatch::Watch::ResultList->new;
$results->add( $complete->{watches}{$name}{complete} );
# Convert hash to result list object
$complete->{watches}{$name} = $results;
}
# Set data to object
$self->{$_} = $complete->{$_} for keys %$complete;
return $self;
}
=head2 param $name, $value
If defined $value set param $name value. Unless return it`s value.
=cut
sub param
{
my ($self, $name, $value) = @_;
die 'Undefined param name' unless $name;
die 'Use public methods' if $name eq 'watches';
$self->{$name} = $value if defined $value;
return $self->{$name};
}
=head2 get $name
Get completed tasks for $name watch
=cut
sub get
{
my ($self, $name) = @_;
# If completed not exists then create new one empty.
$self->{watches}{$name} =
TWatch::Watch::ResultList->new( name => $name, complete => [] )
unless exists $self->{watches}{$name};
return $self->{watches}{$name};
}
=head2 save $project
Save list completed tasks for $project
=cut
sub save
{
my ($self, $project) = @_;
# Prepare watches array
my @watches = $project->watches;
for my $watch ( @watches )
{
my %result = $watch->complete->get;
$watch = {
name => $watch->param('name'),
($watch->complete->count)
?(complete => { result => [values %result] })
:(),
}
};
# Make data to save
my $save = {
name => $project->param('name'),
update => $project->param('update'),
watches => { watch => \@watches },
};
# Get file name to save
my $file = $project->param('cfile');
# Full path consists of completed path and project filename if it is
# new file
$file = (config->get('Complete') =~ m/^(.*)\/.*?$/)[0] .
($project->param('file') =~ m/^.*(\/.*?\.xml)$/)[0]
unless $file;
# Save completed
my $xs = XML::Simple->new(
AttrIndent => 1,
KeepRoot => 1,
RootName => 'project',
NoAttr => 1,
# NoEscape => 1,
NoSort => 1,
ForceArray => ['watch', 'result'],
XMLDecl => 1,
OutputFile => $file,
);
my $xml = $xs->XMLout($save);
return 1;
}
1;
=head1 REQUESTS & BUGS
Roman V. Nikolaev <rshadow@rambler.ru>
=head1 AUTHORS
Copyright (C) 2008 Roman V. Nikolaev <rshadow@rambler.ru>
=head1 LICENSE
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
=cut
|