Skip to content

Commit

Permalink
s/to_string/as_string/ to better match the HTTP::* classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed May 13, 2012
1 parent 580346a commit 372d023
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions lib/HTTP/Headers/ActionPack/Core/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package HTTP::Headers::ActionPack::Core::Base;
use strict;
use warnings;

use overload '""' => 'to_string', fallback => 1;
use overload '""' => 'as_string', fallback => 1;

sub new {
my $class = shift;
Expand All @@ -22,7 +22,7 @@ sub CREATE {

sub BUILD {}

sub to_string {
sub as_string {
my $self = shift;
"$self"
}
Expand All @@ -49,7 +49,7 @@ There is no real user servicable parts in here.
=item C<BUILD>
=item C<to_string>
=item C<as_string>
=back
Expand Down
6 changes: 3 additions & 3 deletions lib/HTTP/Headers/ActionPack/Core/BaseHeaderList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ sub new_from_string {
$list;
}

sub to_string {
sub as_string {
my $self = shift;
join ', ' => map { blessed $_ ? $_->to_string : $_ } $self->iterable;
join ', ' => map { blessed $_ ? $_->as_string : $_ } $self->iterable;
}

sub add { die "Abstract method" }
Expand All @@ -47,7 +47,7 @@ user servicable parts in here.
This accepts a HTTP header string which get parsed
and loaded accordingly.
=item C<to_string>
=item C<as_string>
=back
Expand Down
4 changes: 2 additions & 2 deletions lib/HTTP/Headers/ActionPack/Core/BaseHeaderType.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub new_from_string {
$class->new( @{ (split_header_words( $header_string ))[0] } );
}

sub to_string {
sub as_string {
my $self = shift;
join_header_words( $self->subject, $self->params_in_order );
}
Expand Down Expand Up @@ -99,7 +99,7 @@ Accessor for the unordered hash-ref of params.
This will take an HTTP header string
and parse it into and object.
=item C<to_string>
=item C<as_string>
This stringifys the link respecting the
parameter order.
Expand Down
4 changes: 2 additions & 2 deletions lib/HTTP/Headers/ActionPack/DateHeader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sub new_from_string {
$class->new( header_to_date( $header_string ) );
}

sub to_string { date_to_header( (shift)->{'date'} ) }
sub as_string { date_to_header( (shift)->{'date'} ) }

# implement a simple API
sub second { (shift)->{'date'}->second }
Expand Down Expand Up @@ -76,7 +76,7 @@ Returns the underlying L<Time::Piece> object.
This will take an HTTP header Date string
and parse it into and object.
=item C<to_string>
=item C<as_string>
=item C<second>
Expand Down
4 changes: 2 additions & 2 deletions lib/HTTP/Headers/ActionPack/Link.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sub relation_matches {
}
}

sub to_string {
sub as_string {
my $self = shift;

my @params;
Expand Down Expand Up @@ -123,7 +123,7 @@ object.
This will take an HTTP header Link string
and parse it into and object.
=item C<to_string>
=item C<as_string>
This stringifys the link respecting the
parameter order.
Expand Down
4 changes: 2 additions & 2 deletions lib/HTTP/Headers/ActionPack/MediaTypeList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ sub add_header_value {
$self->add( $q, $mt );
}

sub to_string {
sub as_string {
my $self = shift;
join ', ' => map { $_->[1]->to_string } $self->iterable;
join ', ' => map { $_->[1]->as_string } $self->iterable;
}

sub iterable {
Expand Down
2 changes: 1 addition & 1 deletion lib/HTTP/Headers/ActionPack/PriorityList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sub new_from_string {
$list;
}

sub to_string {
sub as_string {
my $self = shift;
join ', ' => map {
my ($q, $subject) = @{ $_ };
Expand Down
4 changes: 2 additions & 2 deletions t/001-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ isa_ok($pack, 'HTTP::Headers::ActionPack');
my $media_type = $pack->create( 'Content-Type' => 'application/xml;charset=UTF-8' );
isa_ok($media_type, 'HTTP::Headers::ActionPack::MediaType');

is($media_type->to_string, 'application/xml; charset="UTF-8"', '... got the right string');
is($media_type->as_string, 'application/xml; charset="UTF-8"', '... got the right string');

my $links = $pack->create( 'Link' => '</test/tree/1_2>; tag="child", </test/tree/1_1>; tag="child", </test/tree>; rel="up"');
isa_ok($links, 'HTTP::Headers::ActionPack::LinkList');

is($links->to_string, '</test/tree/1_2>; tag="child", </test/tree/1_1>; tag="child", </test/tree>; rel="up"', '... got the right string');
is($links->as_string, '</test/tree/1_2>; tag="child", </test/tree/1_1>; tag="child", </test/tree>; rel="up"', '... got the right string');

done_testing;
18 changes: 9 additions & 9 deletions t/010-media-type.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ sub test_media_type {
is($media_type->major, 'application', '... got the right major portion');
is($media_type->minor, 'xml', '... got the right minor portion');

is($media_type->to_string, 'application/xml; charset="UTF-8"', '... the string representation');
is($media_type->as_string, 'application/xml; charset="UTF-8"', '... the string representation');

my $media_type_2 = HTTP::Headers::ActionPack::MediaType->new('application/xml', => ( 'charset' => 'UTF-8' ));
isa_ok($media_type_2, 'HTTP::Headers::ActionPack::MediaType');
is($media_type_2->to_string, 'application/xml; charset="UTF-8"', '... the string representation');
is($media_type_2->as_string, 'application/xml; charset="UTF-8"', '... the string representation');

ok($media_type->equals( $media_type_2 ), '... these types are equal');
ok($media_type->equals('application/xml; charset=UTF-8'), '... these types are equal');
Expand Down Expand Up @@ -70,7 +70,7 @@ test_media_type(
'... got the right params'
);

is($matches_all->to_string, '*/*', '... the string representation');
is($matches_all->as_string, '*/*', '... the string representation');

ok($matches_all->matches_all, '... this type does match all');
}
Expand All @@ -86,7 +86,7 @@ boundary=----------------------------2c46a7bec2b9]);
'... got the right params'
);

is($multiline->to_string, 'multipart/form-data; boundary="----------------------------2c46a7bec2b9"', '... the string representation');
is($multiline->as_string, 'multipart/form-data; boundary="----------------------------2c46a7bec2b9"', '... the string representation');
}

# test multiple params ...
Expand All @@ -100,7 +100,7 @@ boundary=----------------------------2c46a7bec2b9]);
'... got the right params'
);

is($mt->to_string, 'application/json; v="3"; foo="bar"', '... got the right string representation');
is($mt->as_string, 'application/json; v="3"; foo="bar"', '... got the right string representation');
}

# test a lot of params ...
Expand All @@ -114,7 +114,7 @@ boundary=----------------------------2c46a7bec2b9]);
'... got the right params'
);

is($mt->to_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="123"', '... got the right string representation');
is($mt->as_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="123"', '... got the right string representation');
}

# test with quoted strings
Expand All @@ -128,7 +128,7 @@ boundary=----------------------------2c46a7bec2b9]);
'... got the right params'
);

is($mt->to_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="1,23"', '... got the right string representation');
is($mt->as_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="1,23"', '... got the right string representation');
}
{
my $mt = HTTP::Headers::ActionPack::MediaType->new_from_string('application/json; v=3; foo=bar; q=0.25; testing="1;23"');
Expand All @@ -140,7 +140,7 @@ boundary=----------------------------2c46a7bec2b9]);
'... got the right params'
);

is($mt->to_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="1;23"', '... got the right string representation');
is($mt->as_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="1;23"', '... got the right string representation');
}
{
my $mt = HTTP::Headers::ActionPack::MediaType->new_from_string('application/json; v=3; foo=bar; q=0.25; testing="12\"3\""');
Expand All @@ -152,7 +152,7 @@ boundary=----------------------------2c46a7bec2b9]);
'... got the right params'
);

is($mt->to_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="12\"3\""', '... got the right string representation');
is($mt->as_string, 'application/json; v="3"; foo="bar"; q="0.25"; testing="12\"3\""', '... got the right string representation');
}

done_testing;
Expand Down
6 changes: 3 additions & 3 deletions t/020-priority-list.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sub test_priority_list {
);

is(
$q->to_string,
$q->as_string,
'baz; q="3", foobaz; q="3", gorch; q="2.5", bar; q="2", foo; q="1"',
'... got the right string form'
);
Expand Down Expand Up @@ -81,7 +81,7 @@ test_priority_list(
);

is(
$q->to_string,
$q->as_string,
'application/xml; q="0.7"',
'... got the right string form'
);
Expand All @@ -99,7 +99,7 @@ test_priority_list(
);

is(
$q->to_string,
$q->as_string,
'en-US; q="1", es; q="1"',
'... got the right string form'
);
Expand Down
16 changes: 8 additions & 8 deletions t/030-media-type-list.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'audio/basic; q="1", audio/*; q="0.2"',
'... got the expected string back'
);
Expand All @@ -32,7 +32,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'audio/basic, audio/*; q="0.2"',
'... got the expected string back'
);
Expand All @@ -45,7 +45,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'audio/basic, audio/*; q="0.2"',
'... got the expected string back'
);
Expand All @@ -58,7 +58,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'text/html, text/x-c, text/x-dvi; q="0.8", text/plain; q="0.5"',
'... got the expected string back'
);
Expand All @@ -71,7 +71,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'text/html; level="1", text/html, text/*, */*',
'... got the expected string back'
);
Expand All @@ -84,7 +84,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'text/html; charset="iso8859-1", application/xml',
'... got the expected string back'
);
Expand All @@ -97,7 +97,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'text/html, */*, application/xml; q="0.7"',
'... got the expected string back'
);
Expand All @@ -110,7 +110,7 @@ BEGIN {
isa_ok($list, 'HTTP::Headers::ActionPack::MediaTypeList');

is(
$list->to_string,
$list->as_string,
'application/json; v="2", application/json; v="3"; foo="bar"',
'... got the expected string back'
);
Expand Down
8 changes: 4 additions & 4 deletions t/040-link.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sub test_link {
ok($link->relation_matches('PREVIOUS'), '... relation matching works');

is(
$link->to_string,
$link->as_string,
'<http://example.com/TheBook/chapter2>; rel="previous"; title="previous chapter"',
'... got the string we expected'
);
Expand Down Expand Up @@ -83,7 +83,7 @@ test_link(
ok(!$link->relation_matches('HTTP://example.net/foo'), '... relation matching works');

is(
$link->to_string,
$link->as_string,
'</>; rel="http://example.net/foo"',
'... got the string we expected'
);
Expand Down Expand Up @@ -111,7 +111,7 @@ test_link(
);

is(
$link->to_string,
$link->as_string,
q{</TheBook/chapter2>; rel="previous"; title*="UTF-8'de'letztes%20Kapitel"},
'... got the string we expected'
);
Expand Down Expand Up @@ -139,7 +139,7 @@ test_link(
);

is(
$link->to_string,
$link->as_string,
q{</TheBook/chapter4>; rel="next"; title*="UTF-8'de'n%C3%A4chstes%20Kapitel"},
'... got the string we expected'
);
Expand Down
2 changes: 1 addition & 1 deletion t/050-date.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sub test_date {
is( $h->minute, 14, '... got the minute');
is( $h->second, 19, '... got the second');

is( $h->to_string, 'Mon, 23 Apr 2012 14:14:19 GMT', '... got the expected string');
is( $h->as_string, 'Mon, 23 Apr 2012 14:14:19 GMT', '... got the expected string');
}

test_date(
Expand Down

0 comments on commit 372d023

Please sign in to comment.