| 1 | package DJabberd::Plugin::PrivateStorage::SpoolDirectory; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use base 'DJabberd::Plugin::PrivateStorage'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use File::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use URI::Escape; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use File::Slurp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use File::Basename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head2 get_file_name($self, $user, $element) | ||||||||||
| 11 | |||||||||||
| 12 | Get the filename that should hold information for this combination of $user and | ||||||||||
| 13 | $element. The variable are escaped in order to prevent problem with various char, like | ||||||||||
| 14 | "/". | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub get_file_name { | ||||||||
|
Subroutine
get_file_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 0 | my ($self, $user, $element) = @_; | |||||||||
| 20 | 0 | my ($login, $domain) = split(/@/, $user); | |||||||||
| 21 | 0 | $login = uri_escape($login); | |||||||||
| 22 | 0 | $domain = uri_escape($domain); | |||||||||
| 23 | 0 | $element = uri_escape($element); | |||||||||
| 24 | #~ $ perl -MURI::Escape -e 'print uri_escape("http://coin.foo.org/plop:ezez/"),"\n" | ||||||||||
| 25 | #http%3A%2F%2Fcoin.foo.org%2Fplop%3Aezez%2F | ||||||||||
| 26 | 0 | return $self->{directory} . "/$domain/$login/$element.xml" | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | =head2 set_config_directory($self, $val) | ||||||||||
| 30 | |||||||||||
| 31 | Set the directory that will be used a base of the spool directory. | ||||||||||
| 32 | It will be created if it doesn't exist. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub set_config_directory { | ||||||||
|
Subroutine
set_config_directory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 37 | 0 | my ($self, $val) = @_; | |||||||||
| 38 | 0 | $self->{directory} = $val; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | =head2 finalize($self) | ||||||||||
| 42 | |||||||||||
| 43 | Check that plugin was correctly initialized. | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub finalize { | ||||||||
|
Subroutine
finalize: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||
| 50 | 0 | ▶ | die "Missing directory" if not defined $self->{directory}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | # TODO ensure permisison ? | ||||||||||
| 52 | 0 | ▶ | mkpath($self->{directory}) if ! -d $self->{directory}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | ▶ | die if ! -d $self->{directory}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | =head2 load_privatestorage($self, $user, $element) | ||||||||||
| 57 | |||||||||||
| 58 | Load the element $element for $user from memory. | ||||||||||
| 59 | |||||||||||
| 60 | =cut | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub load_privatestorage { | ||||||||
|
Subroutine
load_privatestorage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 63 | 0 | my ($self, $user, $element) = @_; | |||||||||
| 64 | 0 | my $filename = $self->get_file_name($user, $element); | |||||||||
| 65 | 0 | ▶ | return undef if ! -f $filename; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | return read_file($filename); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | =head2 store_privatestorage($self, $user, $element, $content) | ||||||||||
| 70 | |||||||||||
| 71 | Store $content for $element and $user in memory. | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub store_privatestorage { | ||||||||
|
Subroutine
store_privatestorage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 76 | 0 | my ($self, $user, $element, $content) = @_; | |||||||||
| 77 | 0 | my $filename = $self->get_file_name($user, $element); | |||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | mkpath(dirname($filename)) if ! -d dirname($filename); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 0 | write_file($filename, $content->as_xml); | |||||||||
| 82 | } | ||||||||||
| 83 | 2 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||