]> Dogcows Code - chaz/graphql-client/commitdiff
rename class attribute to transport_class
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Mon, 16 Mar 2020 00:27:41 +0000 (18:27 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Mon, 16 Mar 2020 00:52:41 +0000 (18:52 -0600)
lib/GraphQL/Client.pm
t/client.t

index edbb64e4ddc05c6c9e185cdcfc46503bd5e2e3ae..ff8f720cd88d4545f668b79e9c9dd3c5a411d6d5 100644 (file)
@@ -83,15 +83,15 @@ sub url {
     $self->{url};
 }
 
     $self->{url};
 }
 
-sub class {
+sub transport_class {
     my $self = shift;
     my $self = shift;
-    $self->{class};
+    $self->{transport_class};
 }
 
 sub transport {
     my $self = shift;
     $self->{transport} //= do {
 }
 
 sub transport {
     my $self = shift;
     $self->{transport} //= do {
-        my $class = $self->_transport_class;
+        my $class = $self->_autodetermine_transport_class;
         eval { load $class };
         if ((my $err = $@) || !$class->can('execute')) {
             $err ||= "Loaded $class, but it doesn't look like a proper transport.\n";
         eval { load $class };
         if ((my $err = $@) || !$class->can('execute')) {
             $err ||= "Loaded $class, but it doesn't look like a proper transport.\n";
@@ -116,15 +116,16 @@ sub _url_protocol {
     return $protocol;
 }
 
     return $protocol;
 }
 
-sub _transport_class {
+sub _autodetermine_transport_class {
     my $self = shift;
 
     my $self = shift;
 
-    return _expand_class($self->{class}) if $self->{class};
+    my $class = $self->transport_class;
+    return _expand_class($class) if $class;
 
     my $protocol = $self->_url_protocol;
     _croak 'Failed to determine transport from URL' if !$protocol;
 
 
     my $protocol = $self->_url_protocol;
     _croak 'Failed to determine transport from URL' if !$protocol;
 
-    my $class = lc($protocol);
+    $class = lc($protocol);
     $class =~ s/[^a-z]/_/g;
 
     return _expand_class($class);
     $class =~ s/[^a-z]/_/g;
 
     return _expand_class($class);
@@ -247,25 +248,25 @@ Note: Setting the L</unpack> attribute affects the response shape.
 
 The URL of a GraphQL endpoint, e.g. C<"http://myapiserver/graphql">.
 
 
 The URL of a GraphQL endpoint, e.g. C<"http://myapiserver/graphql">.
 
-=attr class
+=attr unpack
 
 
-The package name of a transport.
+Whether or not to "unpack" the response, which enables a different style for error-handling.
 
 
-By default this is automatically determined from the protocol portion of the L</url>.
+Default is 0.
 
 
-=attr transport
+See L</ERROR HANDLING>.
 
 
-The transport object.
+=attr transport_class
 
 
-By default this is automatically constructed based on the L</class>.
+The package name of a transport.
 
 
-=attr unpack
+This is optional if the correct transport can be correctly determined from the L</url>.
 
 
-Whether or not to "unpack" the response, which enables a different style for error-handling.
+=attr transport
 
 
-Default is 0.
+The transport object.
 
 
-See L</ERROR HANDLING>.
+By default this is automatically constructed based on L</transport_class> or L</url>.
 
 =head1 ERROR HANDLING
 
 
 =head1 ERROR HANDLING
 
index 4775b70036f8c44cc12b10285b9f3bb6a15184b3..1dd0cd425ab19c5f519bee7ab5a63e7a791d173d 100755 (executable)
@@ -14,14 +14,14 @@ use GraphQL::Client;
 use MockTransport;
 
 subtest 'transport' => sub {
 use MockTransport;
 
 subtest 'transport' => sub {
-    my $client = GraphQL::Client->new(class => 'http');
-    isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from class');
+    my $client = GraphQL::Client->new(transport_class => 'http');
+    isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from transport_class');
 
     $client = GraphQL::Client->new(url => 'https://localhost:4000/graphql');
     isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from url');
 
 
     $client = GraphQL::Client->new(url => 'https://localhost:4000/graphql');
     isa_ok($client->transport, 'GraphQL::Client::http', 'decide transport from url');
 
-    $client = GraphQL::Client->new(class => 'not a real class');
-    is($client->class, 'not a real class', 'class constructor works');
+    $client = GraphQL::Client->new(transport_class => 'not a real class');
+    is($client->transport_class, 'not a real class', 'transport_class constructor works');
     throws_ok { $client->transport } qr/^Failed to load transport/, 'throws if invalid transport';
 };
 
     throws_ok { $client->transport } qr/^Failed to load transport/, 'throws if invalid transport';
 };
 
This page took 0.024061 seconds and 4 git commands to generate.