Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:19:26+00:00 2026-05-23T14:19:26+00:00

I have written a perl script that feeds data into a web service. I

  • 0

I have written a perl script that feeds data into a web service.

I have some system tests for the perl script that check that I can interact with the webservice, and these work just fine, but I do not want to be running system tests when I make small changes – I want to run unit tests:

So far I have written a subclass of my importer that simply intercepts the web requests before it actually calls the URL in question and tests that all the inputs are of the right type and form, and this works fine in all cases except where the perl script needs to read the response for instructions, and then proceed to the next steps.

My problem is that I cannot fake a response object.

I’ve tried using HTTP::Response->new, but it keeps complaining about bad header arguments

How do I best FAKE a response object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:19:27+00:00Added an answer on May 23, 2026 at 2:19 pm

    There is no need to mock the HTTP::Response object. They are easy to construct—at least as easy as mocking would be and less likely to introduce bugs into the tests. You need to read the documentation and not just guess at usage.

    You can construct them in code, of course, but what I’ve done in the past more than once is just save the output of curl or a stringified request that was made against an application and parse it back into an object.

    Try playing around with these–

    use warnings;
    use strict;
    use HTTP::Response;
    
    my $response = HTTP::Response->new(204);
    print $response->as_string;
    
    my $other = HTTP::Response->parse(join "", <DATA>);
    print $other->decoded_content, $/;
    
    __DATA__
    HTTP/1.1 200 OK
    Cache-Control: public, max-age=53
    Content-Type: text/html; charset=utf-8
    Expires: Wed, 06 Jul 2011 19:13:54 GMT
    Last-Modified: Wed, 06 Jul 2011 19:12:54 GMT
    Vary: *
    Date: Wed, 06 Jul 2011 19:12:59 GMT
    Content-Length: 198121
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <title>Stack Overflow</title>
      </head>
    <body class="home-page">
      <blockquote>O HAI!</blockquote>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a Perl script that reads some data and generates an OpenOffice
I have written a Perl script that sends data to clients. It works some
I have written a Perl script that performs many one-sample t-tests. I get thousands
I have a Perl script that I've written and can compile it using pp
I have a test generator written in Perl. It generates tests that connect to
I have written a Perl script that runs as a daily crontab job that
I have a script that's written in perl, and executed as CGI. It works
I've just written (in Perl) a simple web service that displays a web form
The situation I am in is that I have written a perl script which
I have a perl script which is used to process some data files from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.