Skip to content

Commit

Permalink
Rename new method to content_type_is, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Jun 29, 2024
1 parent b365532 commit c418357
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Revision history for Kelp
{NEXT}
[New Interface]
- Kelp::Base can now be imported with -attr
- Added is_content_type method to Kelp::Request
- Added content_type_is method to Kelp::Request
- Added a couple of is_* methods to Kelp::Request to match Kelp::Response's interface
* is_text, is_html and is_xml have been added

Expand Down
26 changes: 21 additions & 5 deletions lib/Kelp/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sub is_ajax
return $with =~ m{XMLHttpRequest}i;
}

sub is_content_type
sub content_type_is
{
my ($self, $type) = @_;
return 0 unless $self->content_type;
Expand All @@ -122,22 +122,22 @@ sub is_content_type

sub is_text
{
return $_[0]->is_content_type('text/plain');
return $_[0]->content_type_is('text/plain');
}

sub is_html
{
return $_[0]->is_content_type('text/html');
return $_[0]->content_type_is('text/html');
}

sub is_json
{
return $_[0]->is_content_type('application/json');
return $_[0]->content_type_is('application/json');
}

sub is_xml
{
return $_[0]->is_content_type('application/xml');
return $_[0]->content_type_is('application/xml');
}

sub charset_decode
Expand Down Expand Up @@ -587,10 +587,26 @@ Delete session value:
Returns true if the request was called with C<XMLHttpRequest>.
=head2 content_type_is
Returns true if request has a C<Content-Type> header starting with a passed string.
=head2 is_text
Returns true if the request's content type was C<text/plain>.
=head2 is_html
Returns true if the request's content type was C<text/html>.
=head2 is_json
Returns true if the request's content type was C<application/json>.
=head2 is_xml
Returns true if the request's content type was C<application/xml>.
=head2 charset_decode
Shortcut method, which decodes a string using L</charset> or
Expand Down

0 comments on commit c418357

Please sign in to comment.