spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Is a cyclic dependency solved with require?


For purely object-oriented code, there is no circular dependency problem. You can quite happily have something like:

# AAAA.pm
package AAAA;
use strict;
use warnings;
use BBBB;
sub new {
    my $class = shift;
    my ($i) = @_;
    bless {
        b => $i > 0 ? BBBB->new($i-1) :
$i
    }, $class;
}
1;

# BBBB.pm
package BBBB;
use strict;
use warnings;
use AAAA;
sub new {
    my $class = shift;
    my ($i) = @_;
    bless {
        a => $i > 0 ? AAAA->new($i-1) :
$i
    }, $class;
}
1;

# script.pl
use strict;
use warnings;
use AAAA;
use Data::Dumper;
print Dumper( AAAA->new(4) );

Circular dependencies only become an issue if you need do something with a module at compile-time. Exporters are the most common example of this.


Categories : Perl

Related to : Is a cyclic dependency solved with require?
Ruby: Using require produces "in `require': cannot load such file "
You have an unwanted dot in unit., replace your require with: require File.expand_path("../../test_helper", __FILE__) # Or maybe require File.expand_path("../test_helper", __FILE__)

Categories : Ruby On Rails
Exhaust a list of generators in a cyclic fashion
It looks like you want the roundrobin itertools recipe: def roundrobin(*iterables): "roundrobin('ABC', 'D', 'EF') --> A D E B F C" # Recipe credited to George Sakkis pending = len(iterables) nexts = cycle(iter(it).next for it in iterables) while pending: try: for next in nexts: yield next() except StopIteration: pendin

Categories : Python
How to break shared_ptr cyclic reference using weak_ptr
The classic example of cyclic references is where you have two classes A and B where A has a reference to B which has a reference to A: #include <memory> #include <iostream> struct B; struct A { std::shared_ptr<B> b; ~A() { std::cout << "~A() "; } }; struct B { std::shared_ptr<A> a; ~B() { std::cout << "~B() "; } }; void useAnB() { auto a = std

Categories : C++
Automatically detecting cyclic dependencies with Maven?
One way is to set up a unit test using the JDepend API and assertions corresponding to what you want. JDepend jdepend = new JDepend(); jdepend.addDirectory("target/classes"); jdepend.analyze(); // add assertion here;

Categories : Java
Numpy broadcasting with comparison operator; cyclic iteration
There is a numpy function for this: np.where: In [590]: AR1 Out[590]: array([[0, 0, 0, 0], [0, 0, 5, 0], [0, 0, 0, 0]], dtype=uint32) In [591]: np.where(AR1 >= 5, 0, 1) Out[591]: array([[1, 1, 1, 1], [1, 1, 0, 1], [1, 1, 1, 1]]) So, you could define: def Spin1(n, N) : value = n + 1 return np.where(value > N, 0, value) NumPy also pro

Categories : Python
Recently Add
SSL error calling Perl web service via https using LWP
SOAP::Lite always faults in debug mode
perl referencing a hash outside of the scope that populated it (histogram)
Perl script to print out all the lines containing a keyword and the line below it
PERL Unicode Escape string pass from command line argument wrong output
Perl process crashes after handling signal
Marpa: Can I explicitly disallow keywords as identifiers?
Perl: Import text, containing ÅÄÖ, from file
error using perl - Proc::ProcessTable. works in cmd line, not in .pl file
DBIx::Class chaining resultsets with same table in prefetch
Time as input, print timetable in Perl
compare values of different tables perl
Automatically increasing ID generation using PERL
Syntax Error, first line after dostuff
Delete files in a folder using Perl
Perl '-d' operator is not detecting a directory
Perl appending text to new line
write_timeout in IO::Socket::Timeout
Using ForkManager and Perl properly?
Is a cyclic dependency solved with require?
Posting metric to google analytics from perl script
How can I check if a user enters my page the first time?
Sorting arrays of intervals in perl?
Perl: How to get the link target of a soundcloud feed mp3
Uninitialized value in concatenation
Perl code - pipe "|" in `open()` statement
perl command line backticks with matrix
Perl OO - Creating a list of objects
extract gene-id + function annotation from .gff
How to receive parameters and values from POST method in Perl CGI?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.