1 package SL::Webdav::Object;
4 use parent qw(Rose::Object);
8 use Rose::Object::MakeMethods::Generic (
9 scalar => [ qw(filename webdav) ],
10 'scalar --get_set_init' => [ qw(version basename extension) ],
14 ($_[0]->parse_filename)[0];
18 ($_[0]->parse_filename)[1];
22 ($_[0]->parse_filename)[2];
28 my $name = $self->filename;
29 my $version_re = $self->webdav->version_scheme->extract_regexp;
30 my $sep = $self->webdav->version_scheme->separator;
32 my $extension = $name =~ s/\.(\w+?)$// ? $1 : '';
33 my $version = $name =~ s/\Q$sep\E($version_re)$// ? $1 : '';
36 return ($basename, $version, $extension);
39 sub full_filedescriptor {
42 File::Spec->catfile($self->webdav->webdav_path, $self->filename);
46 DateTime->from_epoch(epoch => ($_[0]->stat)[8]);
50 DateTime->from_epoch(epoch => ($_[0]->stat)[9]);
56 open my $fh, '<:raw', $self->full_filedescriptor or die "could not open " . $self->filename . ": $!";
68 my $file = $_[0]->full_filedescriptor;
75 my $base_path = $ENV{'SCRIPT_NAME'};
76 $base_path =~ s|[^/]+$||;
78 my $file = $self->filename;
79 my $path = $self->webdav->webdav_path;
80 my $is_directory = -d "$path/$file";
82 $file = join('/', map { $::form->escape($_) } grep { $_ } split m|/+|, "$path/$file");
83 $file .= '/' if ($is_directory);
85 return "$base_path/$file";
96 SL::Webdav::Object - Webdav object wrapper
100 use SL::Webdav::Object;
102 my $object = SL::Webdav::Object->new(filename => $filename, webdav => $webdav);
104 my $data_ref = $object->data;
105 my $mtime = $object->mtime;
107 my $basename = $object->basename;
108 my $version = $object->version;
109 my $extension = $object->extension;
111 my $link = $object->href;
115 This is a wrapper around a single object in the webdav. These objects are
116 thought about as immutable, and all manipulation will instead happen in the
117 associated L<SL::Webdav::File>.
125 Returns the basename with version and extension stripped.
129 Returns the version string.
133 Returns the extension.
137 L<DateTime> wrapped stat[8]
141 L<DateTime> wrapped stat[9]
145 Ref to the actual data in raw encoding.
149 URL relative to the web base dir for download.
151 =item C<full_filedescriptor>
153 Fully qualified path to file.
159 L<SL::Webdav>, L<SL::Webdav::File>
167 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>