I am using a Graph object and saving it to a database. To save it to the database I am using Storable's nfreeze. The vertices's are inside-out objects (using Class::Std::Storable). It looks like it is supposed to work but I keep getting method errors when I try to get it from the database. It looks like it does not load itself back correctly as an inside-out object.

(in cleanup) Can't locate object method "get_id" via package "Atlas::System::Device::Interface" at C:/Perl/site/lib/Atlas.pm line 676 (Atlas) is my base module for this object

Listed below is my module, could any tell me if they have a better approach than what I am doing right now?

package Atlas::Incident::Network::Graph; use strict; use warnings; use English( -no_match_vars ); use Graph; use Scalar::Util qw(blessed); use Storable qw( nfreeze thaw ); use base 'Atlas::Config'; use Atlas::System; my $ID = '0000000001'; my $insert_graph = 0; my $graph; my $routers; my $self = {}; ################################################# sub network { return $graph } ################################################# sub routers { return $routers } ################################################# sub _fetch_network_graph { my $sql = "SELECT object FROM Impact_Graphs WHERE id = ?"; $graph = $self->dbh->selectrow_array( $sql, {}, $ID ); if (not $graph) { $insert_graph = 1; return; }; my $value = thaw( $graph ); return $value; } ################################################# sub build { $graph = Graph->new(); $routers = Atlas::System->record_search({ order_by => 'name', system_type => 'Router', }); return if not $routers; ROUTER: for my $router (@{$routers}) { $graph->add_vertex( $router ); next ROUTER if not $router->interfaces; for my $interface ( @{$router->interfaces} ) { $graph->add_edge( $router, $interface ); } } SYSTEM: for my $router ( @{$routers} ) { next SYSTEM if not $router->interfaces; INTERFACE: for my $interface ( @{$router->interfaces} ) { next INTERFACE if not $interface->connections; for my $connection ( @{$interface->connections} ) { $graph->add_weighted_path( $connection->parent_interface, $connection->get_weight, $connection->child_interface ); } } } return 1; } ################################################# sub new { return $self if blessed $self; bless $self, __PACKAGE__; _fetch_network_graph(); return $self; } ################################################# sub save { my $sql = $insert_graph ? "INSERT Impact_Graphs SET object = ?, id = ?" : "UPDATE Impact_Graphs SET object = ? WHERE id = ?"; $self->dbh->do( $sql, {}, nfreeze( $graph ), $ID ) or return; $insert_graph = 0; return 1; }

In reply to Storing Inside-Out Objects in a Graph by Herkum

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.