Commits

Toby Inkster committed 321b561

Make stringification return the response body (I always wanted this, but it needed an Object::Stash bugfix first); document how to get the URI back as a string.

  • Participants
  • Parent commits 56e3bfe

Comments (0)

Files changed (2)

File examples/stuff.pl

 	->[0]
 	->dump;
 	
+say W(q{ http://json-schema.org/ });
 say Web::Magic->random_jackbauer_fact;
 say Web::Magic->random_jackbauer_factq;

File lib/Web/Magic.pm

 use JSON::JOM::Plugins::Dumper 0   qw//;
 use JSON::JOM::Plugins::JsonPath 0 qw//;
 use LWP::UserAgent 0               qw//;
-use Object::Stash 0.001            qw/_stash/;
+use Object::Stash 0.002            qw/_stash/;
 use PerlX::QuoteOperator 0         qw//;
 use RDF::RDFa::Parser 1.096        qw//;
 use RDF::Trine 0.135               qw//;
 use YAML::Any 0                    qw/Load Dump/;
 
 use overload
-	'%{}' => \&to_hashref,
-	'@{}' => \&to_hashref,
-	'""'  => sub { ${$_[0]} },
+	'%{}'  => \&to_hashref,
+	'@{}'  => \&to_hashref,
+	'""'   => \&content,
 	;
 
 my %F;
 
 =over
 
-=item C<< new ([$method,] $uri [, %args])
+=item C<< new ([$method,] $uri [, %args]) >>
 
 C<< $method >> is the HTTP method to use with the URI, such as 'GET',
 'POST', 'PUT' or 'DELETE'. The HTTP method must be capitalised to
  W(GET => 'http://www.google.com/search?q=kittens');
  W('http://www.google.com/search?q=kittens');
 
+There is experimental support for a quote-like operator similar to
+C<< q() >> or C<< qq() >>:
+
+ use Web::Magic -quotelike => 'qW';
+ qW(http://www.google.com/search?q=kittens);
+
+But it doesn't always behave as expected.
+(See L<https://rt.cpan.org/Ticket/Display.html?id=72822>.)
+
 =head2 Pre-Request Methods
 
 Constructing a Web::Magic object doesn't actually perform a request
 
 =item C<< content >>
 
-The response, as a string.
+The response body, as a string.
+
+Web::Magic overloads stringification calling this method. Thus:
+
+  print W('http://www.example.com/');
+
+will print the body of 'http://www.example.com/'.
 
 =item C<< to_hashref >>
 
   W('http://example.com/')->uri->host;
   W('http://example.com/')->host;
 
+If you need a copy of the URI as a string, two methods are:
+
+  my $magic = W('http://example.com/');
+  my $str_1 = $magic->uri->as_string;
+  my $str_2 = $$magic;
+
+The former perhaps makes for easier to read code; the latter is maybe
+slightly faster code.
+
 =item C<< is_requested >>
 
 Returns true if the invocant has already been requested.
 
   W('http://example.com/')->can('random_jackbauer_fact')
 
+=begin private
+
+=item C<< CAN >>
+
+=item C<< can >>
+
+=end private
+
 =back
 
 =head1 BUGS