1 package SL::Webdav::File;
4 use parent qw(Rose::Object);
8 use Rose::Object::MakeMethods::Generic (
9 scalar => [ qw(webdav filename loaded) ],
12 add_objects => { interface => 'push', hash_key => 'objects' },
17 $_[0]->load unless $_[0]->loaded;
18 my $cmp = $_[0]->webdav->version_scheme->cmp;
19 sort { $cmp->($a, $b) } $_[0]->objects;
28 my @objects = $self->webdav->get_all_objects;
29 my $ref = SL::Webdav::Object->new(filename => $self->filename, webdav => $self->webdav);
30 my ($ref_basename, undef, $ref_extension) = $ref->parse_filename;
32 $self->objects(grep { $_->basename eq $ref_basename && $_->extension eq $ref_extension } @objects);
37 my ($self, %params) = @_;
39 $self->load unless $self->loaded;
41 my $last = $self->latest_version;
45 my $new_version = $self->webdav->version_scheme->first_version;
46 $object = SL::Webdav::Object->new(filename => $self->filename, webdav => $self->webdav);
48 $self->add_objects($object);
50 if (!$self->webdav->version_scheme->keep_last_version($last)) {
51 $params{new_version} = 1;
54 if ($params{new_version}) {
55 my $new_version = $self->webdav->version_scheme->next_version($last);
56 my $sep = $self->webdav->version_scheme->separator;
57 my $new_filename = $last->basename . $sep . $new_version . "." . $last->extension;
58 $object = SL::Webdav::Object->new(filename => $new_filename, webdav => $self->webdav);
60 $self->add_objects($object);
66 open my $fh, '>:raw', $object->full_filedescriptor or die "could not open " . $object->filename . ": $!";
68 $fh->print(${ $params{data} });
83 SL::Webdav::File - Webdav file manipulation
89 my $webdav_file = SL::Webdav::File->new(
90 webdav => $webdav, # SL::Webdav instance
91 filename => 'technical_drawing_AB28375.pdf',
94 # get existing versioned files
95 my @webdav_objects = $webdav_file->versions;
98 my $data = SL::Helper::CreatePDF->create_pdf(...);
99 my $webdav_object = $webdav_file->store(data => \$data);
102 my $webdav_object = $webdav_file->store(data => \$data, new_version => 1);
106 A file in this context is the collection of all versions of a single file saved
107 into the webdav. This module provides methods to access and manipulate these
116 Will return all L<SL::Webdav::Object>s found in this file, sorted by version
117 according to the version scheme used.
119 =item C<latest_version>
121 Returns only the latest version object.
125 Loads objects from disk.
127 =item C<store PARAMS>
129 Store a new version on disk. C<data> is expected to contain a reference to the
130 data to be written in raw encoding.
132 If param C<new_version> is set, force a new version, even if the versioning
133 scheme would keep the old one.
139 L<SL::Webdav>, L<SL::Webdav::Object>
147 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>