Skip to content

Exporting globals/code organization and import conflict #1708

Open
@amishHammer

Description

@amishHammer

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions