Web-MREST

 view release on metacpan or  search on metacpan

lib/Web/MREST/Resource.pm  view on Meta::CPAN

            },
        );

    }

    # add standard properties to the payload
    $declared_status->payload->{'uri_path'} = $self->context->{'uri_path'};
    $declared_status->payload->{'resource_name'} = $self->context->{'resource_name'};
    $declared_status->payload->{'http_method'} = $self->context->{'method'};
    $declared_status->payload->{'found_in'} = {
        package => (caller)[0],
        file => (caller)[1],
        line => (caller)[2]+0,
    };

    # the object is "done": push it onto the context
    $self->push_onto_context( {
        'declared_status' => $declared_status,
    } );
}


=head3 mrest_declared_status_code

lib/Web/MREST/Test.pm  view on Meta::CPAN

Perform the boilerplate tasks that have to be done at the beginning of every
unit. Takes a PARAMHASH with two optional parameters:

    'class' => class into which Web::Machine object is to be blessed
    'sitedir' => sitedir parameter to be passed to Web::MREST::init

=cut

sub initialize_unit {
    my %ARGS = @_;
    note( "Initializing unit " . (caller)[1] . " with arguments " . Dumper( \%ARGS ) );
    my $class = $ARGS{'class'} || undef;
    my %init_options = $ARGS{'sitedir'}
        ? ( 'sitedir' => $ARGS{'sitedir'} )
        : ();

    # zero logfile and tell Log::Any to log to it
    my $log_file_spec = File::HomeDir->my_home . "/mrest.log";
    unlink $log_file_spec;
    Log::Any::Adapter->set( 'File', $log_file_spec );
    $log->init( ident => 'MREST_UNIT_TEST' );

lib/Web/MREST/Test.pm  view on Meta::CPAN

If the HTTP result code is 200, the return value will be a status object, undef
otherwise.

=cut

sub req {
    my ( $test, $code, $method, $resource, $json ) = validate_pos( @_, 1, 1, 1, 1, 0 );
    $log->debug( "Entering " . __PACKAGE__ . "::req" );

    if ( ref( $test ) ne 'Plack::Test::MockHTTP' ) {
        diag( "Plack::Test::MockHTTP object not passed to 'req' from " . (caller)[1] . " line " . (caller)[2] );
        BAIL_OUT(0);
    }

    # assemble request
    my @headers = (
        'accept' => 'application/json',
        'content-type' => 'application/json',
    );
    my $r = llreq( $method, $resource, \@headers, $json );

lib/Web/MREST/Test.pm  view on Meta::CPAN

and resource name without quotes)

=cut

sub docu_check {
    my ( $test, $resource ) = @_;

    #diag( "Entering " . __PACKAGE__ . "::docu_check with argument $resource" );

    if ( ref( $test ) ne 'Plack::Test::MockHTTP' ) {
        diag( "Plack::Test::MockHTTP object not passed to 'req' from " . (caller)[1] . " line " . (caller)[2] );
        BAIL_OUT(0);
    }

    my $tn = "docu_check $resource ";
    my $t = 0;
    my ( $docustr, $docustr_len );
    #
    # - straight 'docu' resource
    my $status = req( $test, 200, 'demo', 'POST', '/docu', <<"EOH" );
{ "resource" : "$resource" }



( run in 0.623 second using v1.01-cache-2.11-cpan-1e74a51a04c )