| 1 | package Webservice::OVH::Helper; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | Webservice::OVH::Helper | ||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | Some Helper Methods | ||||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | =head1 METHODS | ||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 36 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 18 | 36 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 19 | 36 | ▶ | use Carp qw{ carp croak }; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | 36 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | =head2 construct_filter | ||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | Helper method to construct uri parameter | ||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | =over | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | =item * Parameter: key => value | ||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | =item * Return: VALUE | ||||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | =item * Synopsis: Webservice::OVH::Helper->construct_filter(); | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | =back | ||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 0 | ▶ | sub construct_filter { | ||||||||||||||||||||
|
Subroutine
construct_filter: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | 0 | my ( $class, %params ) = @_; | |||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | 0 | my @params = keys %params; | |||||||||||||||||||||
| 44 | 0 | my @values = values %params; | |||||||||||||||||||||
| 45 | 0 | ▶ | my $filter = scalar @values ? '?' : ""; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | 0 | my $pairs = []; | |||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 0 | foreach my $param (@params) { | |||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | 0 | my $value = $params{$param}; | |||||||||||||||||||||
| 52 | 0 | ▶ | next unless $value; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | 0 | ▶ | $value = $value eq '_empty_' ? "" : $value; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 55 | 0 | push @$pairs, sprintf( "%s=%s", $param, $value ); | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | 0 | my $str = join('&', @$pairs); | |||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | 0 | ▶ | return $str ? "?" . $str : ""; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | =head2 construct_filter | ||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | Returns a DateTime Object. | ||||||||||||||||||||||
| 67 | Methods uses special pattern to match ovhs DT format. | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | =over | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | =item * Parameter: $str_datetime - datetime string, $locale - locale like 'en_EN', $timezone - timezone | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | =item * Return: DateTime | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | =item * Synopsis: Webservice::OVH::Helper->parse_datetime("2016-05-15T19:30:23", 'de_DE', 'Europe/Berlin'); | ||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | =back | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | 0 | ▶ | sub parse_datetime { | ||||||||||||||||||||
|
Subroutine
parse_datetime: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | 0 | my ( $class, $str_datetime, $locale, $timezone ) = @_; | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 0 | ▶ | my $strp = DateTime::Format::Strptime->new( | ||||||||||||||||||||
|
Condition0%0/4
$locale || 'de_DE'
$timezone || 'Europe/Berlin'
MC/DC0%0/1
$locale || 'de_DE'
$locale
MC/DC0%0/1
$timezone || 'Europe/Berlin'
$timezone
Truth table0%0/2
A
A= $locale
Truth table0%0/2
A
A= $timezone
| |||||||||||||||||||||||
| 86 | pattern => '%FT%T', | ||||||||||||||||||||||
| 87 | locale => ( $locale || 'de_DE' ), | ||||||||||||||||||||||
| 88 | time_zone => ( $timezone || 'Europe/Berlin' ), | ||||||||||||||||||||||
| 89 | on_error => 'croak', | ||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 0 | return $strp->parse_datetime($str_datetime); | |||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | 0 | ▶ | sub parse_date { | ||||||||||||||||||||
|
Subroutine
parse_date: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | 0 | my ( $class, $str_datetime, $locale, $timezone ) = @_; | |||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | 0 | ▶ | my $strp = DateTime::Format::Strptime->new( | ||||||||||||||||||||
|
Condition0%0/4
$locale || 'de_DE'
$timezone || 'Europe/Berlin'
MC/DC0%0/1
$locale || 'de_DE'
$locale
MC/DC0%0/1
$timezone || 'Europe/Berlin'
$timezone
Truth table0%0/2
A
A= $locale
Truth table0%0/2
A
A= $timezone
| |||||||||||||||||||||||
| 100 | pattern => '%F', | ||||||||||||||||||||||
| 101 | locale => ( $locale || 'de_DE' ), | ||||||||||||||||||||||
| 102 | time_zone => ( $timezone || 'Europe/Berlin' ), | ||||||||||||||||||||||
| 103 | on_error => 'croak', | ||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | 0 | return $strp->parse_datetime($str_datetime); | |||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | =head2 format_datetime | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | Returns a date time string fitting ovhs requirements | ||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | =over | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | =item * Parameter: $dt - DateTime object | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | =item * Return: VALUE | ||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | =item * Synopsis: my $dt_str = Webservice::OVH::Helper->format_datetime(DateTime->today()); | ||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | =back | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | 0 | ▶ | sub format_datetime { | ||||||||||||||||||||
|
Subroutine
format_datetime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | 0 | my ( $class, $dt ) = @_; | |||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | 0 | return $dt->strftime('%FT%T%z'); | |||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||
| 131 | |||||||||||||||||||||||
| 132 | 0 | ▶ | sub trim { | ||||||||||||||||||||
|
Subroutine
trim: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 133 | |||||||||||||||||||||||
| 134 | 0 | my ( $class, $string ) = @_; | |||||||||||||||||||||
| 135 | |||||||||||||||||||||||
| 136 | 0 | $string =~ s/^\s+|\s+$//g; | |||||||||||||||||||||
| 137 | |||||||||||||||||||||||
| 138 | 0 | return $string; | |||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | 0 | ▶ | sub rtrim { | ||||||||||||||||||||
|
Subroutine
rtrim: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | 0 | my ( $class, $string ) = @_; | |||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | 0 | $string =~ s/\s+$//; | |||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | 0 | return $string; | |||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||
| 149 | |||||||||||||||||||||||
| 150 | 0 | ▶ | sub ltrim { | ||||||||||||||||||||
|
Subroutine
ltrim: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | 0 | my ( $class, $string ) = @_; | |||||||||||||||||||||
| 153 | |||||||||||||||||||||||
| 154 | 0 | $string =~ s/^\s+//; | |||||||||||||||||||||
| 155 | |||||||||||||||||||||||
| 156 | 0 | return $string; | |||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||
| 158 | |||||||||||||||||||||||
| 159 | 36 | 1; | |||||||||||||||||||||