NAME

Concierge::Desk::UnavailableComponent - Stand-in substituted for a failed optional Concierge desk component

VERSION

v0.10.0

SYNOPSIS

my $comp = Concierge::Desk::UnavailableComponent->new(
    name   => 'organizations',
    reason => $@,
);

my $result = $comp->add_record('acme', {});
# { success => 0, message => "Component 'organizations' unavailable: ..." }

DESCRIPTION

Concierge::Desk::UnavailableComponent is substituted by "open_desk" in Concierge in place of an optional component whose new() died at desk-open time. It accepts any method call and returns a uniform failure hashref, so application code that always checks $result->{success} continues to work without special-casing a missing component.

METHODS

new

my $comp = Concierge::Desk::UnavailableComponent->new(
    name   => $component_name,
    reason => $failure_reason,
);

Constructor. Stores name (the component's key in the desk's components config) and reason (typically the $@ captured from the failed new() call) on the blessed object.

AUTOLOAD

Any method call other than DESTROY is caught by AUTOLOAD and returns:

{ success => 0, message => "Component '$name' unavailable: $reason" }

regardless of arguments.

DESTROY

Explicit no-op, so object teardown does not fall through to AUTOLOAD.

THE can()/isa() CAVEAT

AUTOLOAD intercepts calls to methods that don't otherwise exist, but it does not make can() or isa() report true for those methods. This class deliberately does not override can() or isa() to paper over that gap. Code that probes a component before calling it --

if ($comp->can('add_record')) {
    $comp->add_record(...);
}

-- will find can('add_record') false on an UnavailableComponent stand-in, and so will silently skip the call instead of getting the uniform failure hashref. The correct pattern, per "UNAVAILABLE COMPONENT SUBSTITUTION" in Concierge::Desk::Component, is to call the method directly and check $result->{success}, never to probe with can/isa first.

SEE ALSO

Concierge::Desk::Component -- the contract this class stands in for when a component fails to load.

Concierge -- see open_desk() for where this substitution happens.

AUTHOR

Bruce Van Allen <bva@cruzio.com>

LICENSE

This module is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.