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

Exporting globals/code organization and import conflict #1708

Open
amishHammer opened this issue Apr 15, 2024 · 0 comments
Open

Exporting globals/code organization and import conflict #1708

amishHammer opened this issue Apr 15, 2024 · 0 comments

Comments

@amishHammer
Copy link

amishHammer commented Apr 15, 2024

As there is no longer a :syntax option for import there are no symbol conflicts for application's that export globals from sub modules. In this example we have a MyApp::Schemas module that contains a large number of OpenAPI shared schema objects (using Dancer2::Plugin::OpenAPI). These schema's are then re-used in other route handling modules.

App minimal layout
lib/MyApp.pm lib/MyApp/V1/Object1.pm lib/MyApp/Schemas.pm

MyApp.pm

package MyApp;
use Dancer2 appname => 'MyApp';
use Dancer2::Plugin::OpenAPI;
use MyApp::V1::Object1;

1;

MyApp/V1/Object1.pm

package MyApp::V1::Object1;
use Dancer2 appname => 'MyApp';
use Dancer2::Plugin::OpenAPI;
use MyApp::Schemas;

prefix '/v1/object1';

openapi_path {
    tags => [ "Object1" ],
    description => "Get all of the objects currently registered",
    responses => {
        200 => {
            content => {
                "application/json" => {
                    schema => {
                        type => "object",
                        properties => { id => $IdSchema },
                    },
                },
            },
        },
    },
},
get '/' => sub {
    return { objects => { id => '0a244ad8-4ac6-4213-925c-dcb04d998803' } };
};
1;

MyApp/Schemas.pm

package MyApp::Schemas;
use Dancer2 appname => 'MyApp';
use Dancer2::Plugin::OpenAPI;

use Exporter qw/import/;
our @EXPORT = qw/$IdSchema/;

our $IdSchema = openapi_definition Id => {
    type => "string",
    description => "String containing the objects UUID",
};

When running the app you get the following error:

Subroutine MyApp::Schemas::import redefined at /usr/lib/x86_64-linux-gnu/perl-base/Exporter.pm line 30 (#1)

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

1 participant