Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to create scalar bare services using references? #69

Open
djerius opened this issue Feb 4, 2019 · 4 comments
Open

unable to create scalar bare services using references? #69

djerius opened this issue Feb 4, 2019 · 4 comments

Comments

@djerius
Copy link
Contributor

djerius commented Feb 4, 2019

Hi,

I'm like to create a bare service via a reference which returns a scalar. I can't seem to be able to come up with a configuration that works. Here's some code and a configuration:

use strict;
use warnings;

use Data::Dumper;
use Beam::Wire;

package Class {
    sub new { return bless {}, $_[0] }
    sub time { return 20 }
}
$INC{'Class.pm'} = 'Class.pm';    # so module looks like it's been loaded.

my %call = (
    '$ref'  => 'evt2data',
    '$call' => 'time',
);

my %config = (
    'evt2data' => {
        'class' => 'Class',
    },
    'time' => [ { %call } ],
    'time1' => { %call },
    'time2' => { value  => { %call } },
);

my $wire = Beam::Wire->new( config => \%config );

for my $service ( qw[ time time1 time2 ] ) {
    eval { say Dumper( $wire->get( $service ) ) }
      or say STDERR $@;
}

With the following output:

$VAR1 = [
          20
        ];

Invalid config for service 'time1': Service configuration incomplete. Missing one of "class", "value", "config"
$VAR1 = {
          '$ref' => 'evt2data',
          '$call' => 'time'
        };

Is what I'm asking for possible?

@preaction
Copy link
Owner

I'm surprised it doesn't work, but it wouldn't be terribly difficult to add. It'd be another option in create_service. Presently only $class, $extends, and $value are allowed to define services, but adding $ref makes sense.

@XSven
Copy link

XSven commented Nov 15, 2021

Any idea when this feature could be implemented?

@iamalnewkirk
Copy link

In Rewire I called this ability extends. @preaction once upon a time we talked about rewriting the Beam::Wire engine.

@djerius
Copy link
Contributor Author

djerius commented Jan 29, 2024

Here's an attempt at this: #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants