Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:47:23+00:00 2026-06-08T22:47:23+00:00

I’m trying to parse different XML that is returned depending on the command given

  • 0

I’m trying to parse different XML that is returned depending on the command given in a class method… but I think I’m getting a bit deep here.

I’d like to be able to use other methods and access attributes of the instance from WITHIN the XML::Twig handler.

This is an instance method I defined in a Moose object in order to get and parse XML using XML::Twig:

sub get_xmls {
    my $self   = shift;
    my $sehost = shift;
    my $symm   = shift;

    $self->log->info("Getting XMLs for $sehost - $symm");

    my %SYMMAPI_CALLS = (
            "Config"   => {
                'command'    => "symcfg list -sid ${symm} -v",
                'handlers'   => {
                                 'SymCLI_ML/Symmetrix' => $self->can('process_symm_info')
                            },
                'dbtable'    => "inv_emc_array"
            },
            "Pools"  => {
                'command'    => "symcfg -sid ${symm} list -pool -thin",
                'handlers'   => {
                                  'DevicePool' => $self->can('process_symm_pool')
                            },
                'dbtable'    => "inv_emc_pool"
                     }
                );

    foreach my $key (sort(keys %SYMMAPI_CALLS)) {

            my $xmldir   = $self->xmlDir;
            my $table    = $SYMMAPI_CALLS{$key}{'tbl'};
            my $handlers = $SYMMAPI_CALLS{$key}{'handlers'};
            my $command  = $SYMMAPI_CALLS{$key}{'command'};
            my $xmlfile  = qq(${xmldir}/${sehost}/${key}_${symm}.xml);

            $self->log->info("\t$key");

            if(!-d qq(${xmldir}/${sehost})) {
                mkdir(qq(${xmldir}/${sehost}))
                    or $self->log->logdie("Cant make dir ${xmldir}/${sehost}: $!");
            }

            $self->_save_symxml($command, $xmlfile);

            $self->twig(new XML::Twig( twig_handlers => $handlers ));

            $self->log->info("Parsing $xmlfile...");

            $self->twig->parsefile($xmlfile);

            $self->log->info("\t\t...finished.");
            die "Only running the first config case for now...";
    }
}

And the definition of one of the handlers (not really doing anything right now while I figure out how to do this correctly:

sub process_symm_info {
    my ($twig, $symminfo) = @_;

    print Dumper($symminfo);

}

This works just fine, but what I’d like is for the process_symm_info method to have access to $self and all the methods and attributes $self brings along with it. Is that possible? Am I doing this all wrong? Since I can specify specific parts of the XML it’d be nice to be able to do other things with that data from within the handler.

This is sort of my first venture into Perl Moose (if you couldn’t already tell).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:47:25+00:00Added an answer on June 8, 2026 at 10:47 pm

    Currently, you have

    handlers => {
        DevicePool => $self->can('process_symm_pool'),
    },
    

    Change it to

    handlers => {
        DevicePool => sub { $self->process_symm_pool(@_) },
    },
    

    The variable $self will be captured by the anonymous sub. This is why the following works:

    sub make {
        my ($s) = @_;
        return sub { return $s };
    }
    
    my $x = make("Hello, ");
    my $y = make("World!\n");
    print $x->(), $y->();  # Hello, World!
    

    The world of closures, that is 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.