Hello PerlMonks, I would like to know the way we can export symbolic subroutine "'/got/:site_id' => sub" and use its array or variable in order to utilize the same at other package for calling APIs. I can return the value that i am trying access but I have dependencies of landing page from the same subroutine. Your advices are appreciated. Please check my code below

package webapp; use Dancer2; use Op; use Op1; use URI; use Net::OAuth2::Client; use HTML::Entities; use Data::Dumper; use parent 'Exporter'; our $accestoken = ""; our @access_token; sub client { Net::OAuth2::Profile::WebServer->new( client_id => 'xxxxxxxxxxxxxxxxxxx', client_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', authorize_url => 'https://dev.oktapreview.com/oauth2/ +v1/authorize', access_token_url => 'https://dev.oktapreview.com/oauth2/v1/token +', redirect_uri => uri_for ("/got/$site_id"), grant_type => 'authorization_code', ); } get '/got/:site_id' => sub { my $p = params->{code}; defined params->{code} or print "Error: Missing access code"; my $id = route_parameters->get('site_id'); my $site_id = params->{$id}; @access_token = client($site_id)->get_access_token($p); template 'query2' => { 'title' => 'webapp' }; }; post '/'=> sub { my $r2 = Op::result3({OKTAUsersList => param('OKTA-Users-List'), Email => param('Email')}); template result3 => { title => 'webapp', result3 => $r2 } }; true;

My other code where i would like to utilize @access_token in $value2 in api_call3 through my post

package Op; use strict; use warnings; use Win32::Process; use Storable; use IO::Socket::SSL; use REST::Client; use JSON::Parse ':all'; use MIME::Base64; use Term::ReadKey; use Data::Dumper; use MIME::Lite; use Net::SMTP; use webapp qw/@access_token/; use Spreadsheet::XLSX; use Spreadsheet::ParseXLSX; use Excel::Writer::XLSX; sub api_call3 { $client->default_header( 'content-type' => 'application/json' ); $client->default_header( 'Accept' => 'application/json' ); $client->default_header( 'Authorization' => "Bearer $value2" ); $client->request(HTTP::Request->new('GET', "$_[0]")); } sub result3 { my ($args) = @_; my $oktadev = $args->{OKTAUsersList}; my $email = $args->{Email}; my @responsetext; my @responsalter; $strExcelFilename1 = "C:/PERL/" . "OKTADev-Profile-User-Details" . + $date . ".xlsx"; my $apiurlapplog2 = "https://dev.oktapreview.com" ."/api/v1/users? +"; my $response = api_call3($apiurlapplog2); print "Response:\n"; @responsetext = parse_json ($response->content); my $workbook = Excel::Writer::XLSX->new( $strExcelFilename1 ); for my $i (0..$#responsetext) { my $responseid = $responsetext[$i]{id}; my $responsests = $responsetext[$i]{status}; if ($responsests ne "DEPROVISIONED") { $worksheet->write(0, 0, 'OKTA-ID'); $worksheet->write(0, 1, 'FIRST NAME'); $worksheet->write(0, 2, 'LAST NAME'); $worksheet->write($r, 0, $responseid); $worksheet->write($r, 1, $responsetext[$i]{profile}{firstName}); $worksheet->write($r, 2, $responsetext[$i]{profile}{lastName}); $r += 1; } } }

I would like to use the @access_token value in my other package. Please let me know if you need other details


In reply to Need to know the export process of Dancer 2 app. by chandantul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.