Skip to content
Snippets Groups Projects
Commit a73b6570 authored by Anton Soldatov's avatar Anton Soldatov
Browse files

* WebService::Redmine 0.0.6

* Added perlcritic tests
parent c4a693b0
Branches
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ use 5.010; ...@@ -4,7 +4,7 @@ use 5.010;
use strict; use strict;
use warnings; use warnings;
our $VERSION = '0.04'; our $VERSION = '0.06';
use URI; use URI;
use URI::QueryParam; use URI::QueryParam;
...@@ -253,6 +253,8 @@ sub new ...@@ -253,6 +253,8 @@ sub new
} }
bless $self, $class; bless $self, $class;
return $self;
} }
=head2 error =head2 error
...@@ -265,7 +267,7 @@ be dispatched into an HTTP request), contains description of the client error. ...@@ -265,7 +267,7 @@ be dispatched into an HTTP request), contains description of the client error.
=cut =cut
sub error { $_[0]->{error} } sub error { return $_[0]->{error} }
=head2 errorDetails =head2 errorDetails
...@@ -281,7 +283,7 @@ be dispatched into an HTTP request), return value is ...@@ -281,7 +283,7 @@ be dispatched into an HTTP request), return value is
=cut =cut
sub errorDetails { $_[0]->{error_details} } sub errorDetails { return $_[0]->{error_details} }
sub _set_error { $_[0]->{error} = $_[1] // ''; return; } sub _set_error { $_[0]->{error} = $_[1] // ''; return; }
...@@ -372,7 +374,7 @@ sub _dispatch_name ...@@ -372,7 +374,7 @@ sub _dispatch_name
my $name = shift // return $self->_set_client_error('Undefined method name'); my $name = shift // return $self->_set_client_error('Undefined method name');
my @args = @_; my @args = @_;
my ($action, $objects) = ($name =~ /^(get|read|create|update|delete)?([A-Za-z]+?)$/); my ($action, $objects) = ($name =~ /^(get|read|create|update|delete)?([A-Za-z]+?)$/x);
if (!$action || $action eq 'read') { if (!$action || $action eq 'read') {
$action = 'get'; $action = 'get';
...@@ -411,8 +413,6 @@ sub _dispatch_name ...@@ -411,8 +413,6 @@ sub _dispatch_name
} }
$objects = $self->_normalize_objects($objects); $objects = $self->_normalize_objects($objects);
delete $self->{expect_single_object};
my $i = 0; my $i = 0;
my @objects; my @objects;
while ($objects =~ /([A-Z][a-z]+)/g) { while ($objects =~ /([A-Z][a-z]+)/g) {
...@@ -423,10 +423,12 @@ sub _dispatch_name ...@@ -423,10 +423,12 @@ sub _dispatch_name
next if $object eq $category; next if $object eq $category;
my $is_last_object = pos($objects) == length($objects);
# We need to attach an object ID to the path if an object is singular and # We need to attach an object ID to the path if an object is singular and
# we either perform anything but creation or we create a new object inside # we either perform anything but creation or we create a new object inside
# another object (createProjectMembership) # another object (e.g. createProjectMembership)
if ($action ne 'create' || pos($objects) != length($objects)) { if ($action ne 'create' || !$is_last_object) {
my $object_id = $args[$i++]; my $object_id = $args[$i++];
return $self->_set_client_error( return $self->_set_client_error(
...@@ -436,22 +438,36 @@ sub _dispatch_name ...@@ -436,22 +438,36 @@ sub _dispatch_name
push @objects, $object_id; push @objects, $object_id;
} }
if (pos($objects) == length($objects)) { # Last object in the chain: $self->_dispatch_last_object($action, $object, $data) if $is_last_object;
}
$data->{path} = join '/', @objects;
return $data;
}
sub _dispatch_last_object
{
my $self = shift;
my $action = shift;
my $object = shift;
my $data = shift;
delete $self->{expect_single_object};
if (length $object) {
if ($action eq 'get' || $action eq 'create') { if ($action eq 'get' || $action eq 'create') {
$self->{expect_single_object} = $object; $self->{expect_single_object} = $object;
} }
if (defined $data->{content} && $self->{no_wrapper_object}) { if ($self->{no_wrapper_object}) {
# Automatically wrap object data, otherwise we pass everything as is: if ($action eq 'create' || $action eq 'update') {
$data->{content} = { # Wrap object data unless we pass everything as is:
$object => $data->{content} $data->{content} = { $object => $data->{content} };
};
} }
} }
} }
$data->{path} = join '/', @objects; return 1;
return $data;
} }
sub _normalize_objects sub _normalize_objects
...@@ -478,9 +494,9 @@ sub _object ...@@ -478,9 +494,9 @@ sub _object
my $object = lc(shift); my $object = lc(shift);
# Process compound words: # Process compound words:
$object =~ s/timeentr/time_entr/ig; $object =~ s/timeentr/time_entr/igx;
$object =~ s/issue(categor|status)/issue_$1/ig; $object =~ s/issue(categor|status)/issue_$1/igx;
$object =~ s/customfield/custom_field/ig; $object =~ s/customfield/custom_field/igx;
return $object; return $object;
} }
......
# BEGIN {
# if (!$ENV{REDMINER_DEVEL}) {
# require Test::More;
# Test::More::plan(skip_all => 'Development tests (REDMINER_DEVEL not set)' );
# }
# }
use strict;
use warnings;
use Test::More;
eval 'use Test::Perl::Critic';
plan skip_all => 'Test::Perl::Critic required to criticise code' if $@;
Test::Perl::Critic->import(-profile => 'xt/perlcritic.rc') if -e 'xt/perlcritic.rc';
all_critic_ok();
severity = 3
verbose = 6
top = 50
theme = pbp || core || bugs || security || maintenance
criticism-fatal = 1
color = 1
allow-unsafe = 1
[-ClassHierarchies::ProhibitAutoloading]
[-Subroutines::RequireArgUnpacking]
[RegularExpressions::RequireExtendedFormatting]
minimum_regex_length_to_complain_about = 15
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment